我有一个关于在MySQL工作台中创建视图的问题。我有错误:保存时“View的SELECT包含FROM子句中的子查询”。
这是我的陈述的副本:
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
知道哪里出错了?
答案 0 :(得分:2)
作为the official documentation says
E.4。对视图的限制
(..)
子视图不能在视图的FROM子句中使用。
一个选项可能是为每个子查询创建一个View。
另一个是修改您的视图,以避免subquerys
子句中的from
答案 1 :(得分:0)
您可以创建子查询的视图并在主视图中调用他