mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
input year, output month
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
WITH params AS (
|
||||
SELECT
|
||||
TO_DATE(NULLIF($2, ''), 'YYYY') AS year,
|
||||
string_to_array(NULLIF($4, ''), ',') AS device_ids
|
||||
)
|
||||
|
||||
SELECT
|
||||
A.device_uuid,
|
||||
TO_CHAR(date_trunc('month', A.event_date), 'YYYY-MM') AS event_month,
|
||||
SUM(A.count_motion_detected) AS total_motion_detected,
|
||||
SUM(A.count_presence_detected) AS total_presence_detected,
|
||||
SUM(A.count_total_presence_detected) AS total_overall_presence
|
||||
FROM public."presence-sensor-daily-device-detection" AS A
|
||||
JOIN params P ON TRUE
|
||||
WHERE A.device_uuid::text = ANY(P.device_ids)
|
||||
AND (
|
||||
P.year IS NULL
|
||||
OR date_trunc('year', A.event_date) = P.year
|
||||
)
|
||||
GROUP BY 1,2
|
||||
ORDER BY 1,2;
|
Reference in New Issue
Block a user