Miguel E
Miguel E

Reputation: 1326

SQLite grouping

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

Upvotes: 1

Views: 199

Answers (1)

bluish
bluish

Reputation: 27292

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

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

Upvotes: 3

Related Questions