www.gsyw.net > sql语句在编号有重复的情况下取另外一个字段数字最大的数据

sql语句在编号有重复的情况下取另外一个字段数字最大的数据

select distinct xx from aa;

create table #test(id int,a varchar(100),b int); insert into #test values (1,'a',100) insert into #test values (1,'b',200) insert into #test values (2,'A',100) insert into #test values (2,'B',500) insert into #test values (2,'D',500) select * from #test aa where not

update T2 set T2.B2=T1.B1 from (Select max(A1) as A1,C1,D1 from T1 group by C1,D1) T3 left join T1 On T3.A1=T1.A1 left join T2 on t1.D1=t2.A2 where t1.C1=2000 我的想法就是 把T1一样的合成一条 找到最大的A1 .然后用找到的A1去从新查一下T1表 .这样就不会有两条一样的数据.

给你个sqlserver写法,要是其他数据库再说,如果你字段名如你上边所示,替换下表名即可 select substring(类别,charindex(' ',类别)+1 , len(类别)-charindex(' ',类别)) 类别,min(库存) from 表名 group by substring(类别,charindex(' ',类别)+1 , len(类别)-charindex(' ',类别))

select username,count(*) from a where datepart(month,timestr)=12 group by username having count(*) = 1 order by 2

假设要查询的表是 A,字段有:id,name,other select A.id,A.name,A.other from A inner join (select max(id) as id from A group by name) as B on A.id=B.id 以上语句就可以实现.我给出测试语句你测试一下吧.--创建表A create table A( id int primary

首先你要确定是哪个字段 如字段A 字段 B 中的值都是abc select * from 表名 where 字段A='abc' and 字段B='abc'

字段a 字段b 字段cSP000016964 5 20SP000016964 7 30SP000016964 1 15SP000017755 4 16SP000017755 8 12最后得到下面结果SP000016964 7 30SP000017755 8 12--用如下语句即可select z.* from z, (select a,max(b) as max_b from z

select 字段 from 表 group by 字段 having count(1)>1

select * from table where a=(select max(a) from table group b)看下这个语句查出来 是不是你想删的数据,如果是的话delete table from table a,(select * from table where a=(select max(a) from table group b)) b where a.a=b.a

相关搜索:

网站地图

All rights reserved Powered by www.gsyw.net

copyright ©right 2010-2021。
www.gsyw.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com