【发布时间】:2016-08-23 12:33:58
【问题描述】:
我需要从两个查询的联合中创建一个表。
这个查询完全符合我的需要:
SELECT portligh_lotteryTest.scores.team FROM portligh_lotteryTest.scores ORDER BY portligh_lotteryTest.scores.count DESC LIMIT 5
union
SELECT portligh_lotteryTest.scores.team FROM portligh_lotteryTest.scores ORDER BY portligh_lotteryTest.scores.count ASC LIMIT 3
添加 create 语句后,我开始收到错误
CREATE TABLE portligh_lotteryTest.cTop8 (team int) AS
(SELECT portligh_lotteryTest.scores.team FROM portligh_lotteryTest.scores ORDER BY portligh_lotteryTest.scores.count DESC LIMIT 5)
union
(SELECT portligh_lotteryTest.scores.team FROM portligh_lotteryTest.scores ORDER BY portligh_lotteryTest.scores.count ASC LIMIT 3)
错误是:
#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '(SELECT portligh_lotteryTest.scores.team FROM portligh_lotteryTest.scores ORDER '附近使用正确的语法
【问题讨论】:
-
为什么选择语句周围有括号?不需要他们。
-
uniol这是错字吗? -
以上都正确。阴影我删除了外部的一组括号 - 然后在 uniol 处得到错误停止
-
创建表 portligh_lotteryTest.cTop8 (team int)AS(SELECT portligh_lotteryTest.scores.team FROM portligh_lotteryTest.scores ORDER BY portligh_lotteryTest.scores.count DESC LIMIT 5) union all (SELECT portligh_lotteryTest.scores.team FROM portligh_lotteryTest.scores ORDER BY portligh_lotteryTest.scores.count ASC LIMIT 3)