为联合查询创建表 - 语法错误

时间:2016-08-23 12:33:59

标签: mysql mysql-error-1064

我需要从两个查询的联合创建一个表。

此查询完全符合我的要求:

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服务器版本相对应的手册,以便在'附近使用正确的语法(SELECT portligh_lotteryTest.scores.team FROM portligh_lotteryTest.scores ORDER' at line 1

1 个答案:

答案 0 :(得分:0)

您可以尝试以下查询: -

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 all
 SELECT portligh_lotteryTest.scores.team FROM portligh_lotteryTest.scores ORDER BY portligh_lotteryTest.scores.count ASC LIMIT 3) 
相关问题