lstd.net
当前位置:首页 >> sql去重求和 >>

sql去重求和

你好!123 selectsum(k.b) from (selectdistincta,b fromtest) k 希望对你有帮助!

--这个事去重后的结果select * from test where id in(select id from(select name,min(id) id from test group by name)a) --这个是去重后的num求和select sum(num) from test where id in(select id from(select name,min(id) id from test group by name)a)

select sum(platform_cap_num) from 表名 where in ( select min(id) from 表名 group by platform_name)

select a,b,count(c) as c1,sum(d) as d1 --C列计数多少个,D列以A,B列为基准求和 from tablename --tablename为表名 group by a,b --以A,B列为基准

我理解太差了,没有看明白……取和最大的前两名select top 2 name from (select name,sum(num) n from tablegroup by name) twhere t.n desc不包含前两名的所有人select name from table where name not in(select top 2 name from (select name,

insert into A select id,sum(fre) as frd from B group by id

先把重复数据查出来 select distinct itemnum from a order by itemnum having count(*)>0 然后把查询出的数据 再插入到B表中麻烦采纳,谢谢!

select name ,company,DATEPART(yyyy,time),sum(score)from tablegroup by name ,company,DATEPART(yyyy,time)order by DATEPART(yyyy,time),name ,companysum()over()的作用,是不改变原来数据条数基础上求和.

select suppliername,foodname,sum(number) number,dj,sum(zj) zj,dtbtime from 表名 group by suppliername,foodname,dtbtime你可别跪了

drop table T_Count create table T_Count(iId int identity(1,1), cValue varchar(30) default '') Go Insert into T_Count(cValue) Select 'a,b,c' union all select 'b,c,d,e' union all select 'a,c,d,f' union all select 'a,c' Go select sum(case when cValue like '%a%'

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