寄存器之间的区别

时间:2014-09-09 15:09:04

标签: sql database postgresql-8.4

我想在不到72小时的时间内回到我的医院,例如:

id_People    id_issue    internation_in       internation_out
444          456789      2014-01-01      2014-01-07
444          465465      2014-02-10      2014-02-12
444          789564      2014-02-13      2014-02-20
  • internation_out之间的区别456789 - internation_in 465465 =少于72hs NO
  • internation_out之间的差异465465-internation_in 789564 =少于72hs是

重复次数小于72 hs = 1

1 个答案:

答案 0 :(得分:0)

如果我理解正确,你想测量某人离开然后返回的时间:

select t.*,
       (case when internation_out + interval '72 hour' >
                  lag(internation_out) over (partition by id_people order by internaion_in)
             then 'YES'
             else 'NO'
        end)
from table t;