By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE group_test
(a varchar(1),
b varchar(1),
c varchar(1));
INSERT INTO group_test
(a,
b,
c)
VALUES ('a',
'r',
'x'),
('a',
's',
'x'),
('b',
'r',
'x'),
('b',
's',
'y');
4 rows affected
SELECT a,
count(DISTINCT c) #
FROM group_test
GROUP BY a;
a | # |
---|---|
a | 1 |
b | 2 |
SELECT a,
b,
count(DISTINCT c) #
FROM group_test
GROUP BY a,
b;
a | b | # |
---|---|---|
a | r | 1 |
b | r | 1 |
a | s | 1 |
b | s | 1 |
SELECT count(DISTINCT c) #
FROM group_test;
# |
---|
2 |