我有一个查询:
select a,count(b) from xyz group by a;
这给了我表中每个“ a”不同值的出现次数。我的问题是如何查询相同的值,但现在又由另一个字段“ c”分组了?
例如:
对于人口:
(b;c;a)
1;2;test1
2;4;test1
3;4;test1
4;4;test1
5;3;test2
5;3;test2
我想得到:
(field 'a';number of occurrences for each value of 'c';total of occurrences for 'a')
test1;2;4
test2;1;2
最佳答案
如果您的意思是“'c'的不同出现次数”,请尝试:
select a, count(distinct c), count(*)
from xyz
group by a;
关于sql - SQLite分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8386587/