我有一张下表,其中列出了不同的运动方式和运动员的国籍。
CREATE table test
(
column01 VARCHAR(255),
column02 VARCHAR(255)
)
INSERT INTO test VALUES('soccer', 'brazilian');
INSERT INTO test VALUES('soccer', 'brazilian');
INSERT INTO test VALUES('soccer', 'argentinian');
INSERT INTO test VALUES('cycling', 'american');
INSERT INTO test VALUES('cycling', 'colombian');
INSERT INTO test VALUES('cycling', 'colombian');
INSERT INTO test VALUES('cycling', 'colombian');
INSERT INTO test VALUES('bascketball', 'american');
INSERT INTO test VALUES('bascketball', 'american');
INSERT INTO test VALUES('bascketball', 'french');
INSERT INTO test VALUES('bascketball', 'spanish');
我想按相同模式的数量以及每种模式的国籍来得到一个结果组。像这样:
column01 | column02
---------+----------
3 | 2
4 | 2
4 | 3
答案 0 :(得分:1)
您似乎想要:
select count(*), count(distinct column2)
from t
group by column1;