首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求SQL,在线,该怎么解决

2012-03-28 
求SQL,急,在线IDCODE502Y1111602Y11111002Y11111602Y11111702Y11111802Y1111求一条DELETE的SQL,后变为IDCO

求SQL,急,在线
ID CODE
502Y1111
602Y1111
1002Y1111
1602Y1111
1702Y1111
18 02Y1111

求一条DELETE的SQL,后变为
ID CODE
502Y1111
1002Y1111
1602Y1111

意思是相连的ID,只要第一条。

[解决办法]

SQL code
declare @t table (ID int,CODE varchar(7))insert into @tselect 5,'02Y1111' union allselect 6,'02Y1111' union allselect 10,'02Y1111' union allselect 16,'02Y1111' union allselect 17,'02Y1111' union allselect 18,'02Y1111'select * from @t where ID in(select min(ID) from (select *,rid=(select count(1) from @t where ID<=a.ID) from @t a) b group by ID-rid)/*ID          CODE----------- -------5           02Y111110          02Y111116          02Y1111*/ 

热点排行