How do I iterate a table according to fixed time intervals in Postgres?
问题 I want to obtain all rows for which, every interval of 48h in a given period of time, are satisfied the following conditions. Every time all of them are true, I put a flag with value 1 for it. This is what I did so far. DO $$ DECLARE i record; CHARTTIME TIMESTAMP; BEGIN FOR i IN SELECT * FROM schema.lab L JOIN schema.icu I ON L.ID = I.ID WHERE L.ITEM = 50912 AND L.CHARTTIME < I.INTIME AND L.CHARTTIME > (I.INTIME - INTERVAL '7 DAY') LOOP CHARTTIME := L.CHARTTIME; FOREACH CHARTTIME IN ARRAY