SELECT ExpendType,SUM(Number),MIN(Total),SUM(Number)*1.0/MIN(Total)
FROM (SELECT ExpendType,Number, Total=(SELECT SUM(Number) FROM dbo.TExpend) FROM dbo.TExpend )f
GROUP BY ExpendType
SELECT ExpendType,SUM(Number),MIN(Total),SUM(Number)*1.0/MIN(Total)
FROM (SELECT ExpendType,Number, Total=(SELECT SUM(Number) FROM dbo.TExpend) FROM dbo.TExpend )f
GROUP BY ExpendType
1楼这个SQL对不,感觉上好像有问题
我的水平有限啊 只想到这种方法 我测试了 好像没啥问题
你哪有更好的方法吗
SQL SERVER下可以这样写. 如果是其它数据库,也可以用子查询来实现
;with ExpSUM
as(
select
ExpendType,
SUM(Number) as ExpendTypeSUM
from TExpend
group by ExpendType
)
select
ExpendType,
ExpendTypeSUM,
(1.0*ExpendTypeSUM)/SUM(ExpendTypeSUM) OVER() as ExpendTypeRatio
from ExpSUM