0

我的数据库有问题

Select * from table where JobId='329188628'

结果:

ID     JobId      ONETID
-----------------------
32951  329188628    532
32951  329188628    532
32951  329188628    532
32951  329188628    532 

我需要删除重复的行。谁能帮帮我吗 ?

4

3 回答 3

3

尝试这个。

with cte(cnt) as
(
  select row_number() over(partition by ID,JobId,ONETID order by getdate())
  from table where JobId='329188628'
)
delete from cte where cnt>1

并且只有 JobId 和 OnetId 用于分组。

with cte(cnt) as
(
  select row_number() over(partition by JobId,ONETID order by getdate())
  from table where JobId='329188628'
)
delete from cte where cnt>1
于 2012-09-18T12:20:42.593 回答
3

请试试:

with c as(
select *, row_number() over(partition by id order by (select 0)) as n
from table where JobID='329188628'
)delete from c
where n > 1;
于 2012-09-18T12:19:49.680 回答
0

使用DISTINCT关键字。

Select DISTINCT * from table where JobId='329188628'
于 2012-09-18T12:20:16.307 回答