我有數據:query url score a www.google.com 3 a www.facebook.com 2 a www.google.com 1我想按域對條目進行“分組”,然后按每個組的最高分對域組進行排序(描述),這樣我得到:query url score a www.google.com 3 a www.google.com 1a www.facebook.com 2 嘗試: select * from table order by Score desc, url asc 不起作用。它給出(沒有明顯變化):query url score a www.google.com 3 a www.facebook.com 2 a www.google.com 1
1 回答

眼眸繁星
TA貢獻1873條經驗 獲得超9個贊
您可以使用窗口函數 - 如果您運行的是 MySQL 8.0:
select *
from mytable
order by max(score) over(partition by url) desc, score desc
在早期版本中,一個選項使用子查詢:
select *
from mytable t
order by
(select max(score) from mytable t1 where t1.url = t.url) desc,
score desc
- 1 回答
- 0 關注
- 137 瀏覽
添加回答
舉報
0/150
提交
取消