sql查询:想同时查询3个井号在各自不同时间段的累计生产天数 单个查询...
发布网友
发布时间:2024-10-21 22:08
我来回答
共1个回答
热心网友
时间:2024-11-18 05:25
一次性查询所有jh、三个时段的语句如下:
select jh
,sum(case when rq between to_date('20140719','yyyymmdd') and to_date('20150311','yyyymmdd') then scsj else 0 end) as scsj2014
,sum(case when rq between to_date('20131109','yyyymmdd') and to_date('20150723','yyyymmdd') then scsj else 0 end) as scsj2013
,sum(case when rq between to_date('20150719','yyyymmdd') and to_date('20160122','yyyymmdd') then scsj else 0 end) as scsj2015
from db1 where jh in('齐5-015','齐7-019','齐11-15')
group by jh
热心网友
时间:2024-11-18 05:30
一次性查询所有jh、三个时段的语句如下:
select jh
,sum(case when rq between to_date('20140719','yyyymmdd') and to_date('20150311','yyyymmdd') then scsj else 0 end) as scsj2014
,sum(case when rq between to_date('20131109','yyyymmdd') and to_date('20150723','yyyymmdd') then scsj else 0 end) as scsj2013
,sum(case when rq between to_date('20150719','yyyymmdd') and to_date('20160122','yyyymmdd') then scsj else 0 end) as scsj2015
from db1 where jh in('齐5-015','齐7-019','齐11-15')
group by jh