为什么不能用子查询呢? select b/(select sum(b) from table) from table where a='ff';partition by 没用过。。
select sum(case A when 'FF' then B Else 0 end)/sum(B) as aa from dbo.TestTB 而且这个也不对 不知道为什么
供参考 select t.deptno,t.ename,t.sal, sum(sal) over (partition by deptno) 部门总和, 100*round(sal/sum(sal) over (partition by deptno),4) "部门份额(%)", sum(sal) over () 总和, 100*round(sal/sum(sal) over (),4) "总份额(%)" from ds_emp t order by t.deptno
select b/(select sum(b) from table) from table where a='ff';partition by 没用过。。
dbo.TestTB
而且这个也不对 不知道为什么
select t.deptno,t.ename,t.sal,
sum(sal) over (partition by deptno) 部门总和,
100*round(sal/sum(sal) over (partition by deptno),4) "部门份额(%)",
sum(sal) over () 总和,
100*round(sal/sum(sal) over (),4) "总份额(%)"
from ds_emp t order by t.deptno