用一个例子解释一个简单的问题:
我有这张桌子:
Country | Name
------------------------------
US | A
US | B
US | A
US | A
FR | A
FR | C
FR | C
我想要结果:
Country | Name | Nname
------------------------------
US | A | 3
US | B | 1
FR | A | 1
FR | C | 2
我使用posgres,我该怎么办?
答案 0 :(得分:0)
这只是一个简单的GROUP BY
:
SELECT country, name, count(*) as nname
FROM table
GROUP BY country, name;
答案 1 :(得分:0)
检查以下
SELECT COUNTRY, NAME, COUNT(NAME) as nname
FROM THIS_TABLE GROUP BY country, name