mtwm.net
当前位置:首页 >> sql分组求和范围 >>

sql分组求和范围

select sum(case d when '1' then (case e when 1 then aa when 2 then bb end ) when '2' then b else 0 end ) from 表 group by c 当然可以,你少了个then

select sum(case d when '1' then a when '2' then b else 0 end ) from 表 group by c

分类求和需要用sun函数.1、如emp表中数据如下:2、现要按照deptno字段分组,求每个分组下的sal的和,可用如下语句:select deptno,sum(sal) from emp group by deptno;3、执行结果:

就是分组求和,用group by和sum()就可以了select 列名1,列名2,sum(列名3) from 表名group by 列名1,列名2

参考sql语句select no ,max(case when type=1 then type) else null end) type1,max(case when type=2 then type) else null end) type2,sum(case when type=1 then sumsource) else null end) source1,sum(case when type=2then sumsource) else null end) source2,from(selct no , type, sum(source) sumsourcegroup by no,type)

select 编号,名称,sum(金额) as 金额,sum(税额) as 税额,代码from 表名group by 编号,名称,代码having (代码='1' and sum(金额)>3000) or (代码='2' and sum(金额)>2000)

SELECT A,SUM(B),SUM(C),SUM(D) FROM N GROUP BY A

select a字段,b字段,c字段,sum(d*e) as 新列,sum(f字段) as f字段,sum(g字段) as g字段 from 表 where h字段>='2015-03-01' and h字段

select 人员,sum(总金额1),sum(总金额2),sum(总金额3) from table group by 人员

可以用数组公式 求a1:a100的奇数行的和 =sum(mod(row(1:100),2)*a1:a100) 偶数行 =sum(mod(row(2:101),2)*a1:a100) ps:数组公式,输入时按ctrl+shift+enter完成

网站首页 | 网站地图
All rights reserved Powered by www.mtwm.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com