2013-07-18 2 views
1

데이터 행에 큰 문제가 있습니다. 데이터 행에 최대 1k 행을 가져올 수 있는데, 8 개가 있어야하며 SQL 쿼리를 사용하면 문제가 발생합니다.) 삭제해야 모든 행은 그 같은 ...IN 문을 사용하여 삭제할 복잡한 SQL 쿼리

편집 : 또한 더 PKEY 그게 전부가 없습니다 왜 중복

select a1.ID, a1.serie, a1.tienda, a1.numtransa, a1.sistema, a1.factura, a1.jfecha, a1.codart from posmov a1 
inner join posmov a2 
on a1.tienda = a2.tienda 
and a1.numtransa = a2.numtransa 
and a1.sistema= a2.sistema 
and a1.factura =a2.factura 
and a1.jfecha = a2.jfecha 
and a1.codart = a2.codart 
and a1.serie =a2.serie 
and a1.ID > a2.ID; 

그러나 나는 그들이 마지막 쿼리에 추가 삭제할 때

delete from posmov 
where ID in (LAST QUERY); 

Msg 116, Level 16, State 1, Line 30 
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. 

사람은 쉬운 방법이있는 경우에, 저를 ENLIGHT 또는 쿼리를 수행하거나 실제로 중복을 삭제할 수 있습니다.

답변

1

IN을 사용할 때마다 ('1', '2', '3') 값을 나열하거나 하위 쿼리에서 단일 필드를 선택할 수 있지만 복수 필드는 선택할 수 없습니다.

delete from posmov 
where ID in (
       select a1.ID 
       inner join posmov a2 
       on a1.tienda = a2.tienda 
       and a1.numtransa = a2.numtransa 
       and a1.sistema= a2.sistema 
       and a1.factura =a2.factura 
       and a1.jfecha = a2.jfecha 
       and a1.codart = a2.codart 
       and a1.serie =a2.serie 
       and a1.ID > a2.ID) 

또는, EXISTS을 사용할 수

delete from posmov 
where EXISTS (LAST QUERY);