SQLite分组

发布于 2024-12-19 14:37:27 字数 403 浏览 2 评论 0原文

我有一个查询:

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

I have a query:

select a,count(b) from xyz group by a;

This gives me the number of occurrences of each different value of 'a' in my table. My question is how can I query the same values but now grouped by another filed 'c'?

Ex:

For population:

(b;c;a)
1;2;test1
2;4;test1
3;4;test1
4;4;test1
5;3;test2
5;3;test2

I'd like to get:

(field 'a';number of occurrences for each value of 'c';total of occurrences for 'a')
test1;2;4 
test2;1;2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如梦亦如幻 2024-12-26 14:37:27

如果您的意思是“'c'的不同出现次数”,那么请尝试:

select a, count(distinct c), count(*) 
from xyz
group by a;

If you mean "number of distinct occurerences of 'c'" then try:

select a, count(distinct c), count(*) 
from xyz
group by a;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文