A    B
----------------
  FF    10 
  SS    20 
现在要拿到 列A 为FF的 B项指标占总指标的比例,用一条sql 语句写出来,且不能带子查询  怎么写
就是要 拿到 10/(10+20)

解决方案 »

  1.   

    为什么不能用子查询呢?
    select b/(select sum(b) from table) from table where a='ff';partition by 没用过。。
      

  2.   

    select sum(case A when 'FF' then B Else 0 end)/sum(B) as aa from 
    dbo.TestTB
    而且这个也不对 不知道为什么 
      

  3.   

    供参考
    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