Tohle je bodnutí do odpovědi. Opravdu potřebuje úplnější údaje, aby bylo možné brát vážně. Tady:
SELECT
*, 1 AS flag
FROM
(SELECT
*,
valuenum - LAG(valuenum, 1) OVER(partition by item) AS diff,
intime - LAG(intime, 1) OVER(partition by item) AS time_diff
FROM
lab L
JOIN
icu I
ON
L.id_sub = I.id
WHERE
L.item = 50912
AND
L.charttime < I.intime AND L.charttime > (I.intime - INTERVAL '7 DAY')
) AS select_diff
WHERE
select_diff.diff > 0.3
AND
select_diff.time_diff <interval '48 hours';