错误1349:View的SELECT包含FROM子句中的子查询

时间:2016-08-27 17:43:30

标签: mysql

SELECT * FROM (SELECT ((DATE_SUB(curdate(), INTERVAL 4 WEEK)) + INTERVAL c.number DAY) AS date_year,

(DATE_FORMAT(((DATE_SUB(curdate(), INTERVAL 4 WEEK)) + INTERVAL c.number DAY),'%w') + 1) as day
FROM (SELECT singles + tens + hundreds number FROM 
( SELECT 0 singles
UNION ALL SELECT   1 UNION ALL SELECT   2 UNION ALL SELECT   3
UNION ALL SELECT   4 UNION ALL SELECT   5 UNION ALL SELECT   6
UNION ALL SELECT   7 UNION ALL SELECT   8 UNION ALL SELECT   9
) singles JOIN 
(SELECT 0 tens
UNION ALL SELECT  10 UNION ALL SELECT  20 UNION ALL SELECT  30
UNION ALL SELECT  40 UNION ALL SELECT  50 UNION ALL SELECT  60
UNION ALL SELECT  70 UNION ALL SELECT  80 UNION ALL SELECT  90
) tens  JOIN 
(SELECT 0 hundreds
UNION ALL SELECT  100 UNION ALL SELECT  200 UNION ALL SELECT  300
UNION ALL SELECT  400 UNION ALL SELECT  500 UNION ALL SELECT  600
UNION ALL SELECT  700 UNION ALL SELECT  800 UNION ALL SELECT  900
) hundreds
) c  
WHERE c.number BETWEEN 0 and 364 ) a

1 个答案:

答案 0 :(得分:4)

虽然您没有提出任何问题,但我尝试猜测:当您尝试在问题中运行查询时,您会在标题中收到错误消息。

正如create view语句中的mysql文档所说:

  

视图定义受以下限制:

     

在MySQL 5.7.7之前,SELECT语句不能包含子查询   FROM子句。

因此,要么将mysql升级到v5.7.7,要么不能在视图的from子句中使用子查询。考虑使用union子查询中的辅助表。