这是我的代码,
Select CAST.first_name, CAST.last_name, `directors winning movies list`.castID, count(*) AwardsWon
From `directors winning movies list`, CAST
WHERE `directors winning movies list`.castID = CAST.castID
Group By `directors winning movies list`.castID
Having count(*)
= (Select Max(cnt)
From (Select count(*) cnt
From `directors winning movies list`
Group By `directors winning movies list`.castID) z)
查询本身正确执行,但是当我尝试创建一个视图并保存它时,我得到错误#1349视图的select子句在from子句中包含一个子查询。有谁知道如何解决这个问题?
答案 0 :(得分:1)
MySQL不允许使用子查询创建视图。 可能的解决方法是为每个子查询创建单独的视图。
例如:
CREATE VIEW movies_view AS
SELECT COUNT(*) cnt
FROM `directors winning movies list`
GROUP BY `directors winning movies list`.castID) z)
CREATE VIEW movies_view_count AS
SELECT MAX(cnt) from movies_view
调用主查询中的movies_view_count
,它应该有效。