From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001
From: Martial Simon <msimon_fr@hotmail.com>
Date: Mon, 15 Sep 2025 01:08:27 +0200
Subject: add: graphs et rushs

---
 graphs/sql/maas/req02.sql | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 graphs/sql/maas/req02.sql

(limited to 'graphs/sql/maas/req02.sql')

diff --git a/graphs/sql/maas/req02.sql b/graphs/sql/maas/req02.sql
new file mode 100644
index 0000000..1d95021
--- /dev/null
+++ b/graphs/sql/maas/req02.sql
@@ -0,0 +1,22 @@
+CREATE TEMPORARY VIEW devices_metrics AS (
+    SELECT
+    device_serial,
+    version_id,
+    logs.id AS log_id,
+    latitude AS lat,
+    longitude AS long,
+    temperature AS temp,
+    battery_percentage AS battery,
+    signal_strength
+    FROM
+    (
+        SELECT serial_number
+        FROM memorin.devices
+        WHERE deactivated_at IS NULL
+    ) AS active,
+    memorin.device_logs AS logs
+    INNER JOIN memorin.device_versions AS v
+    ON version_id = v.id
+    WHERE serial_number = device_serial
+    ORDER BY device_serial, v.released_at DESC, log_id
+);
-- 
cgit v1.2.3

