diff --git a/libs/common/src/sql/procedures/fact_space_occupancy_count/proceduce_select_fact_space_occupancy.sql b/libs/common/src/sql/procedures/fact_space_occupancy_count/proceduce_select_fact_space_occupancy.sql index 1faaa1e..ac6756d 100644 --- a/libs/common/src/sql/procedures/fact_space_occupancy_count/proceduce_select_fact_space_occupancy.sql +++ b/libs/common/src/sql/procedures/fact_space_occupancy_count/proceduce_select_fact_space_occupancy.sql @@ -1,12 +1,12 @@ WITH params AS ( SELECT - TO_DATE(NULLIF($2, ''), 'YYYY-MM-DD') AS event_date, - $4::uuid AS space_id + $1::uuid AS space_id, + TO_DATE(NULLIF($2, ''), 'YYYY-MM') AS event_month ) select psdsd.* from public."presence-sensor-daily-space-detection" psdsd JOIN params P ON true where psdsd.space_uuid = P.space_id -and (P.event_date IS NULL or psdsd.event_date::date = P.event_date) -ORDER BY 1,2 +AND (P.event_month IS NULL OR TO_CHAR(psdsd.event_date, 'YYYY-MM') = TO_CHAR(P.event_month, 'YYYY-MM')) +ORDER BY space_uuid, event_date \ No newline at end of file