我先count到个数,再用count*系数,然后再sum(count()*系数);这样行不通吗
(19*0+3*100+3*50+11*80)/(19+3+3+11)
SELECT (CASE WHEN ISNULL(B.SL,0)=0 THEN 999999999 ELSE B.SUM_/B.SL END) [BB] FROM (
SELECT SUM(a.sl*a.系数) [sum_],SUM(A.SL) [SL] from (
SELECT 月份,count(*) [sl],系数 from 表 group by 月份,系数 )
A
) B
聚合函数不能嵌套使用,但可以分开嵌套查询实现