日期:2014-05-17 浏览次数:20533 次
select sum1/sum2 from
(select UsrA01.E0122 as id,sum(C411F+C411G+C411E+C411P+C411R) sum1 from UsrA41
right join UsrA01 on UsrA41.A0100=UsrA01.A0100
where YEAR(A41Z0)='2013' and month(A41Z0) = '01' and E0122 like '01%' group by UsrA01.E0122) tbl1
left join
(select UsrA01.E0122 as id,sum(C411F+C411G+C411E+C411P+C411R) sum2 from UsrA41
right join UsrA01 on UsrA41.A0100=UsrA01.A0100
where YEAR(A41Z0)='2013' and month(A41Z0) = '02' and E0122 like '01%' group by UsrA01.E012) tbl2
on tbl1.id=tbl2.id
select
case when
(select sum(C411F+C411G+C411E+C411P+C411R) sum2 from UsrA41
right join UsrA01 on UsrA41.A0100=UsrA01.A0100
where YEAR(A41Z0)='2013' and month(A41Z0) = '02' and E0122 like '01%' group by UsrA01.E0122) =0
then 0
else(
select sum1/sum2 from
(select UsrA01.E0122 as id,sum(C411F+C411G+C411E+C411P+C411R) sum1 from UsrA41
right join UsrA01 on UsrA41.A0100=UsrA01.A0100
where YEAR(A41Z0)='2013' and month(A41Z0) = '01' and E0122 like '01%' group by UsrA01.E0122) tbl1
left join
(select UsrA01.E0122 as id,sum(C411F+C411G+C411E+C411P+C411R) sum2 from UsrA41
right join UsrA01 on UsrA41.A0100=UsrA01.A0100
where YEAR(A41Z0)='2013' and month(A41Z0) = '02' and E0122 like '01%' group by UsrA01.E0122) tbl2
on tbl1.id=tbl2.id) end from UsrA01
SELECT sum1 / CASE WHEN sum2 = 0 THEN 1 ELSE sum2 END --这个地方改一下