MySQL命令由COUNT DISTINCT提供

时间:2010-09-24 13:21:30

标签: mysql count distinct

2.8.7
2.8.3
2.8.2
2.8.7
2.8.5
2.8.7
2.8.7
2.8.5
2.6.0
2.8.3
2.6.4
2.6.3
2.8.4
2.8.0
2.6.3
2.8.5
2.8.5
2.8.5
2.6.0
2.8.2

如何根据这些版本的数量提供唯一值版本?

在出口处,我想得到以下内容:

2.8.5 5

2.8.7 4

2.6.0 2

2.6.3 2

2.8.2 2

2.8.3 2

2.8.4 2

2.6.4 1

2.8.0 1

ORDER BY计数唯一版本))

抱歉我的英文不好

4 个答案:

答案 0 :(得分:13)

SELECT
  version,
  COUNT(*) AS num
FROM
  my_table
GROUP BY
  version
ORDER BY
  COUNT(*) DESC

答案 1 :(得分:3)

SELECT version, COUNT(*) FROM tablename
GROUP BY version
ORDER BY COUNT(*) DESC;

或替代语法

SELECT version, COUNT(*) FROM tablename
GROUP BY 1
ORDER BY 2 DESC;

答案 2 :(得分:1)

select version, count(*) from sometable group by version order by count(*) desc;

答案 3 :(得分:-1)

不用担心,你的英语是可以理解的。请在下面找到答案:

> SELECT version, COUNT(version) AS quantity
FROM tablename
GROUP BY version

有关详细信息,请参阅http://www.kelvinese.com

上的答案