可以代替很多游标做的事情。
select str_userid,(sum(case
when (sort<>'MT21' and sort<>'MT22' and sort<>'MS54' and sort<>'MP56')then
(case
when (Isnull(M1,0)/ration)>1.5 then (1.5* Isnull(str_scale,1))
else (Isnull(M1,0)/ration)* Isnull(str_scale,1)
end)
else ((Isnull(M1,0)/ration)* Isnull(str_scale,1))
end)/sum(str_scale))
as m01
from Tongj_VIEW_Menology_Strong
where ration<>0 and ration is not null and year_month='2006'
group by str_userid
order by m01 desc
select str_userid,(sum(case
when (sort<>'MT21' and sort<>'MT22' and sort<>'MS54' and sort<>'MP56')then
(case
when (Isnull(M1,0)/ration)>1.5 then (1.5* Isnull(str_scale,1))
else (Isnull(M1,0)/ration)* Isnull(str_scale,1)
end)
else ((Isnull(M1,0)/ration)* Isnull(str_scale,1))
end)/sum(str_scale))
as m01
from Tongj_VIEW_Menology_Strong
where ration<>0 and ration is not null and year_month='2006'
group by str_userid
order by m01 desc
浙公网安备 33010602011771号