MySQL返回列名和计数

时间:2012-09-20 06:58:45

标签: mysql

这是我的表格样本:

Column1 | Column2 | Column3
================================
Data1   | 2Data  | 3Data
Data1   | 2data2 | 3data2
Data1   | 2data3 | 3data3
Data1   | 2data4 | 3data4
Data2   | 2data5 | 3data5
Data2   | 2data6 | 3data6
Data2   | 2data7 | 3data7

我想要的结果是,

Column1 | Count
===============
Data1   | 4
Data2   | 3

这可能吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

SELECT Column1, COUNT(*)
FROM your_table
GROUP BY Column1