SQL If else语句处理当前时间

时间:2019-06-28 15:27:48

标签: sql oracle

我有此SQL,它可以准确地提取我想要的内容,但是我遗漏了最后一部分。当HRS大于48小时时,我只需要SQL即可显示信息。我试图做一个if else语句,但是我遇到了问题。我列出了我的原始作品,该作品显示了我所需的一切,只是缺少了仅在HRS> 48HRS时才显示的部分。有人可以帮我解决这个问题吗?先感谢您!

Select 
       g.entity as MISTI,
       t.cur_state      as STATE,
       ROUND(((SYSDATE-t.cur_state_dttm)*24),2) AS HRS

From Entity_Grp_Lst g
left outer join trk_id_def t
on g.facility = t.facility
and g.grp_type = t.grp_type
and g.entity=t.entity
and g.grp_type = '720'
WHERE t.cur_state NOT IN ('PROD','NM','TERM','NULL','IDLE', 'YER', 'PENG')
and Entity_Grp_type = '085'
and g.ENTITY_GRP = 'MET'
order by g.entity, t.cur_state_DTTM desc

1 个答案:

答案 0 :(得分:1)

您应该添加过滤器:

Select 
       g.entity as MISTI,
       t.cur_state      as STATE,
       ROUND(((SYSDATE-t.cur_state_dttm)*24),2) AS HRS

From Entity_Grp_Lst g
left outer join trk_id_def t
on g.facility = t.facility
and g.grp_type = t.grp_type
and g.entity=t.entity
and g.grp_type = '720'
WHERE t.cur_state NOT IN ('PROD','NM','TERM','NULL','IDLE', 'YER', 'PENG')
and Entity_Grp_type = '085'
and g.ENTITY_GRP = 'MET'
AND ROUND(((SYSDATE-t.cur_state_dttm)*24),2) > 48  -- here
order by g.entity, t.cur_state_DTTM desc