SQL——多条相似内容只取一条
作者:互联网
代码
--sql多条相似内容取一条 --首先创建测试数据 if object_id('tempdb..#t') is not null drop table #t create table #t ( time int, total int, name varchar(50) ) insert into #t values (100,1000,'zhangsan') insert into #t values (100,1001,'lisi') insert into #t values (100,1002,'wangwu') insert into #t values (101,1003,'zhaoliu') insert into #t values (101,1004,'sunqi') insert into #t values (102,1005,'hello') select * from #t --取一条--取的是total最大的 select * from #t as a where not exists( select 1 from #t where a.time = time and a.total <total)
标签:insert,into,多条,values,SQL,100,total,只取,select 来源: https://www.cnblogs.com/fabao/p/12827703.html