欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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