I have 3 tables named houses
, trees
, rivers
. All of these tables have city_id
column. I want to group total counts by cities. Cities are in another table.
My database is postgresql.
city_name trees houses rivers
City-1 1000 200 1
City-2 300 100 2
City-3 4000 210 4
I can get for trees
SELECT
city.name as city_name,
count(*) as trees
FROM trees as t, cities as city
WHERE t.city_id = city.city_id
GROUP BY city.name
But I could not join three tables in sama query.