UNION 無法將兩個結果與同一列合併
P粉647504283
P粉647504283 2024-04-03 00:23:39
0
1
416

在這裡輸入圖像描述我試著將這兩個查詢合併在同一個顯示結果中,但Mysql系統一直說UNION不能在這個位置。如果聯合不起作用,我該如何組合這兩個查詢?

P粉647504283
P粉647504283

全部回覆(1)
P粉329425839

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 
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!