作业帮 > 英语 > 作业

oracle 查询优化

来源:学生作业帮 编辑:大师作文网作业帮 分类:英语作业 时间:2024/09/22 17:24:50
oracle 查询优化
select count(*),sum(bal) from rpt_xd where substr(beg_date,5,2)= substr('20130131',5,2) and substr(beg_date,1,4)=substr('20130131',1,4) and term_mon3 and term_mon6 and term_mon12
各位能帮我把它变成一句话吗 只有后面的term_mon条件不同而已 主要就是查询每段term_mon的count(*)和sum(bal)
oracle 查询优化
晕死,你那个20130131都知道是查2013年1月份的了,你就直接='201301'就好了,substr用多了会造成查询速度缓慢的竖着显示就union all就好了,像楼上那位说的那样,横着显示这样select sum(case when term_mon<3 then 1 else 0 end) 小于3数量,
sum(case when term_mon<3 then bal else 0 end) 小于3值,
sum(case when term_mon>3 and term_mon<6 then 1 else 0 end) 大于3小于6数量,
sum(case when term_mon>3 and term_mon<6 then bal else 0 end) 大于3小于6值,
sum(case when term_mon>6 and term_mon<12 then 1 else 0 end) 大于6小于12数量,
sum(case when term_mon>6 and term_mon<12 then bal else 0 end) 大于6小于12值,
sum(case when term_mon>12 then 1 else 0 end) 大于12数量,
sum(case when term_mon>12 then bal else 0 end) 大于12值
from rpt_xd where substr(beg_date,1,6)= '201301'