Publier Globinours 1.0.0-rc.3
This commit is contained in:
parent
ea8c24d622
commit
9a2b4068da
325 changed files with 38230 additions and 20 deletions
34
migrations/011_weight_alerts.sql
Normal file
34
migrations/011_weight_alerts.sql
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
DROP VIEW IF EXISTS v_animals_weight_alerts;
|
||||
|
||||
CREATE VIEW v_animals_weight_alerts AS
|
||||
SELECT
|
||||
a.id AS animal_id,
|
||||
|
||||
-- dernier poids
|
||||
(
|
||||
SELECT m.value
|
||||
FROM measurements m
|
||||
WHERE m.animal_id=a.id AND m.type='weight'
|
||||
ORDER BY m.id DESC
|
||||
LIMIT 1
|
||||
) AS last_weight,
|
||||
|
||||
-- poids de référence ~30 jours avant : le plus récent <= J-30
|
||||
(
|
||||
SELECT m.value
|
||||
FROM measurements m
|
||||
WHERE m.animal_id=a.id AND m.type='weight'
|
||||
AND date(m.measured_at) <= date('now','-30 day')
|
||||
ORDER BY date(m.measured_at) DESC, m.id DESC
|
||||
LIMIT 1
|
||||
) AS w30_weight,
|
||||
|
||||
(
|
||||
SELECT m.measured_at
|
||||
FROM measurements m
|
||||
WHERE m.animal_id=a.id AND m.type='weight'
|
||||
AND date(m.measured_at) <= date('now','-30 day')
|
||||
ORDER BY date(m.measured_at) DESC, m.id DESC
|
||||
LIMIT 1
|
||||
) AS w30_date
|
||||
FROM animals a;
|
||||
Loading…
Add table
Add a link
Reference in a new issue