mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
space_energy_consumed_procedure
This commit is contained in:
@ -0,0 +1,22 @@
|
||||
WITH params AS (
|
||||
SELECT
|
||||
NULLIF($1, '')::uuid AS space_id,
|
||||
NULLIF($2, '')::text AS start_month, -- Format: 'MM-YYYY'
|
||||
NULLIF($3, '')::text AS end_month
|
||||
)
|
||||
|
||||
SELECT
|
||||
B.space_device_uuid AS space_id,
|
||||
A.month,
|
||||
SUM(A.energy_consumed_kW::numeric) AS total_energy_consumed_KW,
|
||||
SUM(A.energy_consumed_A::numeric) AS total_energy_consumed_A,
|
||||
SUM(A.energy_consumed_B::numeric) AS total_energy_consumed_B,
|
||||
SUM(A.energy_consumed_C::numeric) AS total_energy_consumed_C
|
||||
FROM public."power-clamp-energy-consumed-monthly" AS A
|
||||
JOIN public.device AS B
|
||||
ON A.device_uuid::TEXT = B."uuid"::TEXT
|
||||
JOIN params P ON TRUE
|
||||
WHERE B.space_device_uuid = P.space_id
|
||||
AND (P.start_month IS NULL OR TO_DATE(A.month, 'MM-YYYY') >= TO_DATE(P.start_month, 'MM-YYYY'))
|
||||
AND (P.end_month IS NULL OR TO_DATE(A.month, 'MM-YYYY') <= TO_DATE(P.end_month, 'MM-YYYY'))
|
||||
GROUP BY 1, 2;
|
@ -0,0 +1,11 @@
|
||||
SELECT
|
||||
B.space_device_uuid AS space_id,
|
||||
A."date",
|
||||
SUM(A.energy_consumed_kW::numeric) AS total_energy_consumed_KW,
|
||||
SUM(A.energy_consumed_A::numeric) AS total_energy_consumed_A,
|
||||
SUM(A.energy_consumed_B::numeric) AS total_energy_consumed_B,
|
||||
SUM(A.energy_consumed_C::numeric) AS total_energy_consumed_C
|
||||
FROM public."power-clamp-energy-consumed-daily" AS A -- I want to change the source table in the future.
|
||||
JOIN public.device AS B
|
||||
ON A.device_uuid::TEXT = B."uuid"::TEXT
|
||||
GROUP BY 1, 2;
|
Reference in New Issue
Block a user