我試圖執行這個查詢:如何使用MySQL UNION內UNION ALL
(
SELECT co.id as offerId, co.title, co.details, co.link, co.reference, co.rank
FROM club_offer co
WHERE co.id IN (31, 791, 360, 382)
GROUP BY offerId
UNION
SELECT co.id as offerId, co.title, co.details, co.link, co.reference, co.rank
FROM club_offer co
WHERE co.id IN (869, 376, 201, 1246)
GROUP BY offerId
ORDER BY rank DESC
)
UNION ALL
(
SELECT co.id as offerId, co.title, co.details, co.link, co.reference, co.rank
FROM club_offer co
WHERE co.id IN (117, 168, 193, 204, 330, 377, 378, 379, 380, 381, 452, 931, 980, 1100, 1146, 1147, 1190, 1247)
GROUP BY offerId
ORDER BY rank DESC
)
,但我得到的錯誤:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION
所以,我想,要麼我使用錯誤的語法或我正在嘗試做一些無法完成的事情。我猜這個SQL小提琴不需要這個,很有可能有經驗的人會馬上看到什麼是錯的。
有人可以幫忙嗎?謝謝
刪除'ORDER BY's – Lamak
沒有幫助..... –
爲什麼GROUP BY時,沒有聚合函數被使用?此外,MySQL可以在GROUP BY中使用別名嗎? – jarlh