Reputation: 1797
Suppose that we have a sample table
c1 | c2
--------------
a | b
a | b
a | c
a | c
a | c
d | e
d | e
How can we turn this table into the following format
c1 | c2 | c3
--------------------------
a | b | 2
a | c | 3
d | e | 2
where c3
contains the count of c2
based on distinct c1
value.
Upvotes: 0
Views: 1440
Reputation: 1269503
This is a group by
with two keys:
select c1, c2, count(*)
from t
group by c1, c2;
Upvotes: 4