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
30
migrations/009_weight_trend_distinct.sql
Normal file
30
migrations/009_weight_trend_distinct.sql
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
DROP VIEW IF EXISTS v_animals_weight_trend;
|
||||
|
||||
CREATE VIEW v_animals_weight_trend AS
|
||||
SELECT
|
||||
a.id AS animal_id,
|
||||
|
||||
(
|
||||
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,
|
||||
|
||||
(
|
||||
SELECT m2.value
|
||||
FROM measurements m2
|
||||
WHERE m2.animal_id = a.id
|
||||
AND m2.type='weight'
|
||||
AND m2.value != (
|
||||
SELECT m3.value
|
||||
FROM measurements m3
|
||||
WHERE m3.animal_id = a.id AND m3.type='weight'
|
||||
ORDER BY m3.id DESC
|
||||
LIMIT 1
|
||||
)
|
||||
ORDER BY m2.id DESC
|
||||
LIMIT 1
|
||||
) AS prev_weight
|
||||
FROM animals a;
|
||||
Loading…
Add table
Add a link
Reference in a new issue