计算并分组表中列出的每个城镇的次数

时间:2016-04-24 16:17:45

标签: sql oracle-apex

SELECT PEOPLE.TOWNKEY, TOWN_LOOKUP.TOWN FROM PEOPLE
INNER JOIN TOWN_LOOKUP
ON PEOPLE.TOWNKEY = TOWN_LOOKUP.PK
 ORDER BY TOWN

当前表格输出:

enter image description here

1 个答案:

答案 0 :(得分:0)

您完全错过group by子句:

SELECT     tl.town, COUNT(*)
FROM       people p
INNER JOIN town_lookup ON p.townkey = tl.pk
GROUP BY   tl.town
ORDER BY   tl.town