假设我有一个植物表:
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
?