SQL分组查询做相关统计
程序员文章站
2022-03-03 23:52:19
...
根据项目名称分组得到相关数据统计
select row_number() over(order by lxmc) as 编号, lxmc 项目名称,sum(ssj) as 单价,sum(sdj) as 订单价,sum(hzs) as 成本价,sum(hjs) as 折扣价,isnull(sum(ssf),0) as 批发价, count(lxmc) as 数量 from Y_gcdak where lxmc!='' and lxmc is not null group by lxmc
group by lxmc 根据项目名称分组
row_number() over(order by lxmc) 根据项目名称分组后得到的相关序号
isnull(sum(ssf),0) isnull()函数的作用:得到的值如果是null则替换成0
上一篇: 通过SQL语句向自增字段的ID列插入ID
下一篇: plsq程序设计--函数