如何计算mysql中的不同列?
例如: 通过如何计算mysql中的不同列?,mysql,count,distinct,Mysql,Count,Distinct,例如: 通过选择查询,我得到了以下结果: columnA columnB type1 typea type2 typea type3 typeb type4 typec type5 typed type6 typed type7 typed 使用DISTINCT我只得到DISTINCT结果,但我还想得到每个DISTINCT的总数 现在我想得到 typea,typeb,typec and typed. 就像: columnB total typea 2 type
选择查询
,我得到了以下结果:
columnA columnB
type1 typea
type2 typea
type3 typeb
type4 typec
type5 typed
type6 typed
type7 typed
使用DISTINCT
我只得到DISTINCT结果
,但我还想得到每个DISTINCT的总数
现在我想得到
typea,typeb,typec and typed.
就像:
columnB total
typea 2
typeb 1
typec 1
typed 3
非常感谢 您可以使用分组依据
按类型获取结果:
SELECT columnB, COUNT(*) AS 'total'
FROM myTable
GROUP BY columnB;
这应该给你确切的结果,你正在寻找
MySQL文档: