【发布时间】:2017-06-01 19:46:18
【问题描述】:
我正在尝试使用 postgres 执行以下操作:
- 计数不同
- 表连接
- 按 hstore 键分组
我不认为我太过分了,但是不同的计数不是按值按组累加的。
Here is the code on rextester.com
到目前为止我所拥有的:
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';
这给了我:
而我想要:
【问题讨论】:
标签: postgresql join count distinct hstore