如何使用别名显示没有错误的天和月 - mysql

问题描述 投票:0回答:1

我正在尝试与工会展示几天和几个月。但是我在下面的代码中有错误:

(SELECT 1 AS id, a+b AS 'days', 2 AS id2, c+e AS 'months' FROM
((SELECT 0 a UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7
UNION SELECT 8 UNION SELECT 9) a, (SELECT 0 b UNION SELECT 10 UNION SELECT 20 UNION SELECT 30) d, 
 (SELECT 2 AS id2, c+e AS 'months' FROM (SELECT 0 c UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) c, 
(SELECT 0 e UNION SELECT 10) m)

它就像:#1248 - Every derived table must have its own alias

我能在这段代码中做些什么或改变什么?感谢任何帮助。

mysql union alias
1个回答
1
投票

您的查询中有一些错误。我想这可能就是你要找的东西:

SELECT 1 AS id, a+b AS 'days', 2 AS id2, months
FROM ((SELECT 0 a UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7
UNION SELECT 8 UNION SELECT 9) a, 
      (SELECT 0 b UNION SELECT 10 UNION SELECT 20 UNION SELECT 30) d, 
      (SELECT 2 AS id2, c+e AS 'months' 
       FROM (SELECT 0 c UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) c, 
             (SELECT 0 e UNION SELECT 10) m
            ) x
      )

Demo on dbfiddle

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.