0

There is this query:

select town, count(town) 
from user
group by town

which returns

Town         Count
Copenhagen   5
NewYork      6
Athens       7

But I would like an additional line which shows all towns number:

Town         Count
Copenhagen   5
NewYork      6
Athens       7
All          18
Ferdossi
  • 77
  • 8

1 Answers1

0

Probably not the best way, but I believe this should work:

WITH counts_by_town AS (
    SELECT town, COUNT(town) AS cnt
    FROM user
    GROUP BY 1
)

SELECT town, cnt
FROM counts_by_town
UNION ALL
SELECT 'All' AS town, SUM(cnt) AS cnt
FROM counts_by_town;
Ricardo Francois
  • 752
  • 7
  • 24