sql的强大

共计 947 个字符,预计需要花费 3 分钟才能阅读完成。

我知道 sql 的查询很复杂,也是很强大,但就没有见过如果强大的,让大家看一句我最近刚写的, 就一句 sql 语句将总数,百分比都出来了!

select t.*,

round(decode(nvl(all_count,0),0,0,send_count/all_count),3)*100 send_count_rate,

round(decode(nvl(all_count,0),0,0,distribute_count/all_count),3)*100 distribute_count_rate,

round(decode(nvl(all_count,0),0,0,success_count/all_count),3)*100 success_count_rate,

round(decode(nvl(all_count,0),0,0,resend_count/all_count),3)*100 resend_count_rate,

round(decode(nvl(all_count,0),0,0,failure_count/all_count),3)*100 failure_count_rate

from

(

select company_name,

sum(case when process_state=1 or process_state=2 or process_state=3 or process_state=4 or process_state=5 then 1 else 0 end) all_count,

sum(case when process_state=1 then 1 else 0 end) send_count,

sum(case when process_state=2 then 1 else 0 end) distribute_count,

sum(case when process_state=3 then 1 else 0 end) success_count,

sum(case when process_state=4 then 1 else 0 end) resend_count,

sum(case when process_state=5 then 1 else 0 end) failure_count

from t_pbb_open_task group by company_name

) t

sql 的强大

正文完
 
zhaopeng
版权声明:本站原创文章,由 zhaopeng 2009-05-16发表,共计947字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)