我的 table 是这样的
id views country 1 44 A 2 43 A 3 899 B 4 242 A 5 3204 B etc.
I want to count how many times a country is occurring.
For example in above case country A is occurring 3 times. So for my query I want to be able to correctly show the how many times each record is occurring, but in addition to the count I want to add the views also. In above case I want that country A is occurring 3 times and with views as the sum of 44 + 43 + 242 = 329
, but my query displays only the first views output: 44
.
Here is my query
SELECT count( * ) value, country, concat( country , '_', views ) prod
FROM tableA
GROUP BY prod
最佳答案
SELECT country, COUNT(*), SUM(views) FROM tableA GROUP BY country
查看 sqlfiddle .
关于mysql - 查询分组并创建分组总计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12872306/