2012-09-04 115 views
3

我有關於在MySQL工作臺中創建視圖的查詢。我有錯誤:保存時,「視圖的SELECT包含FROM子句中的子查詢」。視圖的SELECT包含FROM子句中的子查詢MySQL語句

這是我發言的副本:

CREATE VIEW viewMorningReport AS 
select z.AllocationDate, z.LocationName, z.StationName, a.00000100, b.01000200, c.02000300 from 
(SELECT DISTINCT AllocationDate, LocationName, StationName FROM satsschema.employeeslot 
where LocationName = 'T2 PML' 
and StationName is not null) z 
left outer join 
(SELECT AllocationDate, LocationName, StationName, EmpName AS '00000100' FROM  satsschema.employeeslot 
WHERE Assigned = true 
and (EmpTime = '00:00:00' && EmpTime < '01:00:00')) a 
on z.LocationName = a.LocationName and z.StationName = a.StationName 
left outer join 
(SELECT AllocationDate, LocationName, StationName, EmpName AS '01000200' FROM satsschema.employeeslot 
WHERE Assigned = true 
and (EmpTime = '01:00:00' && EmpTime < '02:00:00')) b 
on a.LocationName = b.LocationName and a.StationName = b.StationName 
left outer join 
(SELECT AllocationDate, LocationName, StationName, EmpName AS '02000300' FROM satsschema.employeeslot 
WHERE Assigned = true 
and (EmpTime = '02:00:00' && EmpTime < '03:00:00')) c 
on b.LocationName = c.LocationName and b.StationName = c.StationName 

任何想法,在哪裏呢?

+2

的可能重複[MySQL的:使用子查詢視圖FROM子句中的限制] (http://stackoverflow.com/questions/206062/mysql-view-with-subquery-in-the-from-clause-limitation) –

+1

[MySQL:在FROM子句限制中查看子查詢](http: //stackoverflow.com/questions/206062/mysql-view-with-subquery-in-the-from-clause-limitation) –

回答

2

由於the official documentation says

E.4. Restrictions on Views

(..)

Subqueries cannot be used in the FROM clause of a view.

一種選擇,可以創建每個子查詢視圖。 再一個,就是改變你的看法,以避免subquerysfrom子句中

0

你可以創建視圖的子查詢,並呼籲他的主要觀點

相關問題