例如:
使用 select query
我得到以下结果:
columnA columnB
type1 typea
type2 typea
type3 typeb
type4 typec
type5 typed
type6 typed
type7 typed
使用DISTINCT
我只得到了distinct result
,但我还想得到每个distinct的总数
。
现在我想获得总数
typea,typeb,typec and typed.
就像:
columnB total
typea 2
typeb 1
typec 1
typed 3
非常感谢!!
最佳答案
您可以使用 GROUP BY
按类型获取结果:
SELECT columnB, COUNT(*) AS 'total'
FROM myTable
GROUP BY columnB;
这应该会给您准确的结果。
MySQL Documentation: 11.16.1 GROUP BY (Aggregate) Functions
关于mysql - 如何统计mysql中的非重复列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5170147/