채워진 개월을 채우기 위해 채워진 월을 사용하고 개월 단위로 데이터를 그룹화합니다. 문제는 일부 달 (예 : 2016-09-01에서 2016-09-15)을 쿼리하는 데 사용할 수없는 것 같습니다. 항상 전체 월을 계산합니다. 누군가 올바른 방향으로 나를 가리킬 수 있습니까?한 달 동안 generate_series를 작동 시키려면 어떻게해야합니까?
with filled_months AS
(SELECT
month,
0 AS blank_count
FROM generate_series(date_trunc('month',date('2016-09-01')), date_trunc('month',date('2016-09-15')), '1 month') AS
month)
SELECT to_char(mnth.month, 'YYYY Mon') AS month_year,
count(distinct places.id)
FROM filled_months mnth
left outer join restaurants
ON date_trunc('month', restaurants.created_at) = mnth.month
left outer join places
ON restaurants.places_id = places.id
WHERE places.id IS NULL OR restaurants.id IS NULL
GROUP BY mnth.month
ORDER BY mnth.month
질문이 명확하지 않습니다. –