select typy,sum(CAST(fee/rate as numeric(12,2))) as groupValue from tb group by typy union all select '总值',sum(CAST(fee/rate as numeric(12,2))) from tb
select typy,sum(case when rate<>0 then round(fee/rate,2) else 0 end) as total from t1 group by typy with rollup
select typy, sum(round(fee/rate,0)) 总和 from T1 group by typy 这个是算的整数。简单些,但前提是rate不能为0或者空
select typy, sum(round(case rate when 0 then 0 else fee/rate end,0)) 总和 from T1 group by typy
select typy,sum(CAST(fee/rate as numeric(12,2))) as groupValue
from tb
group by typy
union all
select '总值',sum(CAST(fee/rate as numeric(12,2)))
from tb
select typy,sum(case when rate<>0 then round(fee/rate,2) else 0 end) as total
from t1 group by typy with rollup
select typy, sum(round(fee/rate,0)) 总和
from T1
group by typy
这个是算的整数。简单些,但前提是rate不能为0或者空
from T1
group by typy