用SQL语句删除重复数?

用SQL语句删除重复数


MMMHUHU
浏览 785回答 2
2回答

呼唤远方

--声明变量Declare @ID Int, @PosNo IntDeclare @Table Table(ID Int,PosNo int)Declare cur Cursor Static READ_ONLY ForSelect ID, PosNoFrom 表Order By EmpID, IDOpen curFetch From cur Into @ID, @PosNoWhile @@FETCH_STATUS = 0BeginIf Exists(Select * From @Table Where PosNo = @PosNo)BeginDelete 表 Where ID = @IDEndElseBeginInsert Into @Table (ID, PosNo)Values (@ID, @PosNo)EndFetch Next From cur Into @ID, @PosNoEndClose curDeAllocate cur

MYYA

select *from (select a.*,row_number() over (parition by Empid,CardNO,MACHNO,POSNUM,type order by id desc) rnfrom table_name a) twhere rn<=1
打开App,查看更多内容
随时随地看视频慕课网APP