1. 程式人生 > >sql 去重

sql 去重

這個我自己寫的,效率什麼的沒考慮過:

DELETE FROM tb_trademarksjaddtype_23 
WHERE row not in 
(
SELECT t.row FROM 
(
SELECT row 
FROM tb_trademarksjaddtype_23 
GROUP BY ann_num,reg_num,rn,type
HAVING COUNT(1) > 1  //將數量>1的取出一個
UNION
SELECT row 
FROM tb_trademarksjaddtype_23 
GROUP BY ann_num,reg_num,rn,type
HAVING COUNT(1) <= 1 //將數量小於等於1的取出來
) t
);