在這裡輸入圖像描述我試著將這兩個查詢合併在同一個顯示結果中,但Mysql系統一直說UNION不能在這個位置。如果聯合不起作用,我該如何組合這兩個查詢?
P粉3294258392024-04-03 11:58:44
https://dev.mysql.com/doc/refman /8.0/en/union.html 說:
就您而言,它看起來像這樣:
(select customer_id, points, state from customers where state = 'CA' order by points desc limit 3) union (select customer_id, points, state from customers where state = 'FL' order by points desc limit 3)
您可能還想了解視窗函數一个>:
select customer_id, points, state from ( select customer_id, points, state, row_number() over (partition by state order by points desc) as rownum from customers where state in ('CA','FL') ) as t where rownum <= 3