我试图找到一个 MySQL 查询,它将在特定字段中找到 DISTINCT 值,计算该值的出现次数,然后按计数对结果进行排序。
示例数据库
id name ----- ------ 1 Mark 2 Mike 3 Paul 4 Mike 5 Mike 6 John 7 Mark
预期结果
name count ----- ----- Mike 3 Mark 2 Paul 1 John 1
SELECT name,COUNT(*) as count FROM tablename GROUP BY name ORDER BY count DESC;