可以說我有一種植物表:集合函數可以在ORDER BY子句中做什麼?
id fruit
1 banana
2 apple
3 orange
我能做到這
SELECT * FROM plant ORDER BY id;
SELECT * FROM plant ORDER BY fruit DESC;
這確實顯而易見的事情。
但是我被這個咬了,這是做什麼的?
SELECT * FROM plant ORDER BY SUM(id);
SELECT * FROM plant ORDER BY COUNT(fruit);
SELECT * FROM plant ORDER BY COUNT(*);
SELECT * FROM plant ORDER BY SUM(1) DESC;
所有這些只返回第一行(id = 1)。
- 發生了什麼事?
- 聚合函數將在
ORDER BY
中派上用場的場景是什麼?
優秀的解釋,謝謝! – nawfal