gpt4 book ai didi

mysql - View的SELECT在FROM子句MySQL语句中包含子查询

转载 作者:可可西里 更新时间:2023-11-01 08:35:53 25 4
gpt4 key购买 nike

我有一个关于在 MySQL Workbench 中创建 View 的问题。保存时出现错误:“ 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

知道哪里出了问题吗?

最佳答案

作为the official documentation says

E.4. Restrictions on Views

(..)

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

一个选项可能是为每个子查询创建一个 View 。另一个是修改您的 View ,以避免 from 子句中的 subquery

关于mysql - View的SELECT在FROM子句MySQL语句中包含子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12256515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com