我在執行 groupby 子句后試圖獲得最大值。
select count(*) as count, store_id from sakila.customer
group by store_id
我對這段代碼的輸出是:
| 數數 | store_id |
|---|---|
| 326 | 1 |
| 273 | 2 |
如何從計數列中獲取最大值?我嘗試了幾件事,但似乎沒有任何效果。
uj5u.com熱心網友回復:
只需對您的結果進行排序并將它們限制為 1:
select count(*) as count, store_id from sakila.customer
group by store_id
order by count desc
limit 1
uj5u.com熱心網友回復:
再次選擇計數結果作為子查詢
select max(count)
from
select count(*) as count, store_id from sakila.customer
group by store_id
) counts
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/339045.html
上一篇:SQL替換型別化XML資料
