有表 table 数据如下id typeId desc
1 101 你
2 101 你
3 101 你
4 102 我
5 102 我
6 103 他
7 103 他
8 104 的
9 104 的我想在这表理获取出数据 如下id typeId desc
1 101 你
4 102 我
6 103 他
8 104 的请问sql语句应该怎么写
1 101 你
2 101 你
3 101 你
4 102 我
5 102 我
6 103 他
7 103 他
8 104 的
9 104 的我想在这表理获取出数据 如下id typeId desc
1 101 你
4 102 我
6 103 他
8 104 的请问sql语句应该怎么写
select id,typeId,desc from table a
where not exists(select 1 from table where id<a.id)
where id = (select top 1 id from table1 where typeId = a.typeId order by id)
select * ,
row_number() over ( partition by typeId order by id asc ) as RowID
from table )
where RowID= 1
where not exists (select 1 id from table1 where typeId = a.typeId and id < a.id)
select id,typeId,desc from table a
where not exists(select 1 from table where typeId=a.typeId and id<a.id)
(
id int,
typeId int,
[desc] varchar(10)
)
insert into tb values(1,101,'你')
insert into tb values(2,101,'你')
insert into tb values(3,101,'你')
insert into tb values(4,102,'我')
insert into tb values(5,102,'我')
insert into tb values(6,103,'他')
insert into tb values(7,103,'他')
insert into tb values(8,104,'的')
insert into tb values(9,104,'的')select min(id) id ,typeId, [desc] from
tb group by typeId , [desc] order by id
drop table tb
/*
id,typeId,desc
1,101,你
4,102,我
6,103,他
8,104,的(4 行受影响)