select productname,simplename,m1,CASE WHEN m2 is not null THEN m2 ELSE 0 END as m2,
CASE WHEN m1=0 THEN 0 ELSE round(m2/m1,2) END as bili,temp.earlywarningrule
from
(select
t2.productname,t3.simplename,t4.earlywarningrule,t4.id
,(select sum(branchqty) from b_rp_custproductmonthreport where bmonth = '201505' and CorpSID = t3.corpsid and t2.productid = productid) as m1
,(select sum(branchqty) from b_rp_custproductmonthreport where bmonth = '201506' and CorpSID = t3.corpsid and t2.productid = productid) as m2
from G_ME_ProductInfo t2,g_og_corpinfo t3 ,bw_ct_stateparameter t4
where 1=1
--and t3.corpsid='001000000'
and t3.simplename = '东城区'
order by t3.simplename) temp
where m1 is not null and m1<>0 or m2 is not null and m2<>0 and id=1
and m2>m1/2我想把这段sql做成一个查询的存储过程,怎么写
CASE WHEN m1=0 THEN 0 ELSE round(m2/m1,2) END as bili,temp.earlywarningrule
from
(select
t2.productname,t3.simplename,t4.earlywarningrule,t4.id
,(select sum(branchqty) from b_rp_custproductmonthreport where bmonth = '201505' and CorpSID = t3.corpsid and t2.productid = productid) as m1
,(select sum(branchqty) from b_rp_custproductmonthreport where bmonth = '201506' and CorpSID = t3.corpsid and t2.productid = productid) as m2
from G_ME_ProductInfo t2,g_og_corpinfo t3 ,bw_ct_stateparameter t4
where 1=1
--and t3.corpsid='001000000'
and t3.simplename = '东城区'
order by t3.simplename) temp
where m1 is not null and m1<>0 or m2 is not null and m2<>0 and id=1
and m2>m1/2我想把这段sql做成一个查询的存储过程,怎么写
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货