我有一个 MySql 表:
FRUITS COUNT
apple 4
mango 5
banana 7
apple 8
coconut 1
mango 2
apple 5
我想按数量降序显示水果。如果两个水果名称相同,则显示数量较高的水果。因此结果表应该是:
FRUITS COUNT
apple 8
banana 7
mango 5
coconut 1
这个查询应该是什么?
最佳答案
group by
和 order by
很简单。
select fruits,
max(`count`) `count`
from your_table
group by fruits
order by `count` desc;
关于mysql - 对 MySql 表的列进行排序并仅显示不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42632018/