2016-08-23 53 views
0

我需要從兩個查詢的聯合中創建一個表。爲聯合查詢創建表 - 語法錯誤

此查詢的工作正是我需要它:

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 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」在1號線

+1

爲什麼你在select語句周圍有括號?不需要它們。 – Shadow

+2

'uniol'是這個錯字? –

+0

以上兩個都是正確的。Shadow我刪除了外面的一組parens - 然後在uniol得到錯誤停止 –

回答

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)