I'm trying to do the following with postgres:
- count distinct
- table joins
- group by hstore key
I don't think I'm too far, but the count distinct isn't added up per group by values.
Here is the code on rextester.com
What I have so far:
SELECT COUNT(DISTINCT pets.id),locations.attr -> 'country' as country
FROM pets,photos,locations
WHERE photos.pet_id = pets.id
AND photos.location_id = locations.id
GROUP BY pets.id,locations.attr -> 'country';
Which gives me:
Whereas I want: