日期:2014-05-16 浏览次数:20782 次
select t2.name,
t2.Money1,
t2.Money2,
t2.Money1 - t2.Money2 as poor,
(Round((t2.Money1 - t2.Money2) / t2.Money1, 2)) as poor2
from (select t.name,
(case t.type
when '1' then
sum(t.money)
end) as Money1,
(case t.type
when '2' then
sum(t.money)
end) as Money2
from test2 t) t2
group by t2.name
select t2.name,
t2.Money1,
t2.Money2,
t2.Money1 - t2.Money2 as poor,
(Round((t2.Money1 - t2.Money2) / t2.Money1, 2)) as poor2
from(select t.name,
(if t.type=1 then sum(t.money) end if) as Money1,
(if t.type=2 then sum(t.money) end if) as Money2
from test2 t)t2
group by t2.name