select * from (Select count(*) as count1 from edr_cont_hold_release Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=1 )
union ( Select count(*) as count1 from edr_cont_hold_release Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=2 and ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >1)
union ( Select count(*) as count1 from edr_cont_hold_release Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=3 and ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >2)
union ( Select count(*) as count1 from edr_cont_hold_release Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >3 )
这个sql语句如何优化哇,请高手作答,谢谢
union ( Select count(*) as count1 from edr_cont_hold_release Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=2 and ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >1)
union ( Select count(*) as count1 from edr_cont_hold_release Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=3 and ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >2)
union ( Select count(*) as count1 from edr_cont_hold_release Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >3 )
这个sql语句如何优化哇,请高手作答,谢谢
/*
1.请用sql代码发
2.排版请美观
这是个自定义函数?
直接这样即可.
Select count(*) as count1 from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=1
union
Select count(*) as count1 from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=2 and ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >1
union
Select count(*) as count1 from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=3 and ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >2
union
Select count(*) as count1 from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >3
以下两段,自己试试哪段是正确的.Select count(*) as count1 , 1 px from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=1
union
Select count(*) as count1 , 2 px from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=2 and ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >1
union
Select count(*) as count1 , 3 px from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=3 and ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >2
union
Select count(*) as count1 , 4 px from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >3
order by px或者select * from
(
Select count(*) as count1 , 1 px from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=1
union
Select count(*) as count1 , 2 px from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=2 and ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >1
union
Select count(*) as count1 , 3 px from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) <=3 and ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >2
union
Select count(*) as count1 , 4 px from edr_cont_hold_release
Where cont_status in ('IF','EM') And HOLD_CONDITION = 'DT' And ROUND(TO_NUMBER(release_datetime - cont_in_tml_datetime)) >3
) t
order by px