34,590
社区成员
发帖
与我相关
我的任务
分享
select id=(min)id,name,age from tb t
where not exists(select * from t where [name]=t.[name] and age=t.age)
select id=(min)id,name,age from tb t
where not exists(select * from tb where [name]=tb.[name] and age=tb.age)
select * from tb t
where not exists(select 1 from tb where name=t.name and age=t.age and id<t.id)
select min(id) as id,name,age from 表名 group by name,age
select id=min(id),name,age from 表名 group by name,age
if object_id('tb') is not null
drop table tb
go
create table tb(id int identity(1,1),name varchar(10),age int)
go
insert into tb
select 'a',12 union all
select 'b',11 union all
select 'c',10 union all
select 'a',12 union all
select 'b',11
go
select id,name,age from tb t1 where not exists(select 1 from tb where name=t1.name and age=t1.age and id<t1.id)
if object_id('ta')is not null drop table ta
create table ta(id int,[name] char(1),age int)
insert ta
select 1,'a',12 union all
select 2,'b',11 union all
select 3,'c',10 union all
select 4,'a',12 union all
select 5,'b',11
select * from ta t where not exists(select * from ta where [name]=t.[name] and age=t.age and id<t.id)
select min(id) as id,[name],[age] from t group by name,age
select
*
from
tb t
where
id=(select min(id) from tb where name=t.name and age=t.age )
select * from tb t
where not exists(select * from tb where name=t.name and age=t.age and id<t.id)