对 MySql table 的列进行排序并仅显示不同的值
sort columns of MySql table and show only distinct values
我有一个 MySql table :
FRUITS COUNT
apple 4
mango 5
banana 7
apple 8
coconut 1
mango 2
apple 5
我想按降序显示水果 count.If 两个水果名称相同,然后显示 count.So 较高的水果 结果 table 应该是:
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 table :
FRUITS COUNT
apple 4
mango 5
banana 7
apple 8
coconut 1
mango 2
apple 5
我想按降序显示水果 count.If 两个水果名称相同,然后显示 count.So 较高的水果 结果 table 应该是:
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;