纯sql语句求2个时间段之间的降雨量之和,
发布网友
发布时间:2024-10-12 23:35
我来回答
共1个回答
热心网友
时间:2024-11-24 13:29
select sum(drop) from
(select to_date(flag || ':00','yyyy-mm-dd:hh24') as dt, hour00 as drop from table
union
select to_date(flag || ':01','yyyy-mm-dd:hh24') as dt, hour01 as drop from table
union
select to_date(flag || ':02','yyyy-mm-dd:hh24') as dt, hour02 as drop from table
union
select to_date(flag || ':03','yyyy-mm-dd:hh24') as dt, hour03 as drop from table
union
select to_date(flag || ':04','yyyy-mm-dd:hh24') as dt, hour04 as drop from table
union
select to_date(flag || ':05','yyyy-mm-dd:hh24') as dt, hour05 as drop from table
union
select to_date(flag || ':06','yyyy-mm-dd:hh24') as dt, hour06 as drop from table
union
select to_date(flag || ':07','yyyy-mm-dd:hh24') as dt, hour07 as drop from table
union
select to_date(flag || ':08','yyyy-mm-dd:hh24') as dt, hour08 as drop from table
union
select to_date(flag || ':09','yyyy-mm-dd:hh24') as dt, hour09 as drop from table
union
select to_date(flag || ':10','yyyy-mm-dd:hh24') as dt, hour10 as drop from table
union
select to_date(flag || ':11','yyyy-mm-dd:hh24') as dt, hour11 as drop from table
union
select to_date(flag || ':12','yyyy-mm-dd:hh24') as dt, hour12 as drop from table
union
select to_date(flag || ':13','yyyy-mm-dd:hh24') as dt, hour13 as drop from table
union
select to_date(flag || ':14','yyyy-mm-dd:hh24') as dt, hour14 as drop from table
union
select to_date(flag || ':15','yyyy-mm-dd:hh24') as dt, hour15 as drop from table
union
select to_date(flag || ':16','yyyy-mm-dd:hh24') as dt, hour16 as drop from table
union
select to_date(flag || ':17','yyyy-mm-dd:hh24') as dt, hour17 as drop from table
union
select to_date(flag || ':18','yyyy-mm-dd:hh24') as dt, hour18 as drop from table
union
select to_date(flag || ':19','yyyy-mm-dd:hh24') as dt, hour19 as drop from table
union
select to_date(flag || ':20','yyyy-mm-dd:hh24') as dt, hour20 as drop from table
union
select to_date(flag || ':21','yyyy-mm-dd:hh24') as dt, hour21 as drop from table
union
select to_date(flag || ':22','yyyy-mm-dd:hh24') as dt, hour22 as drop from table
union
select to_date(flag || ':23','yyyy-mm-dd:hh24') as dt, hour23 as drop from table
)
where dt between to_date('2013-11-11:05:00:00','yyyy-mm-dd:hh24:mi:ss') and to_date('2013-11-13:11:00:00','yyyy-mm-dd:hh24:mi:ss');
这样做表会死人的。。。
追问谢谢,虽然有点瑕疵,但思路符合描述,这个拿来做练习的,