你是不是暗恋我,那就给我发个消息呀,让我知道o(∩∩)o
分类: Mysql/postgreSQL
2014-05-30 12:36:02
之前在写删除数据库重复记录的时候没有用存储过程代码如下:
表(book)字段
(id , b_name, b_describe, b_author)
1 a, b, c
2 a, b, c
3 e, r, h
4 e, r, h
5 a, r, c
delete from book
where
b_name in (select t2.b_name from book t2 group by t2.b_name,t2.b_describe,t2.b_author having COUNT(*)>1)
and b_describe age in (select t2.b_describe from book t2 group by t2.b_name,t2.b_describe,t2.b_author having COUNT(*)>1)
and b_author age in (select t2.b_author from book t2 group by t2.b_name,t2.b_describe,t2.b_author having COUNT(*)>1)
and id not in(select MIN(t2.id) from from book t2 group by t2.b_name,t2.b_describe,t2.b_author having COUNT(*)>1)
使用上面的代码可以把完全重复记录删除,但同时也会把第5条记录删除;
后来就改用存储过程的方法如下:
CREATE PROCEDURE del_pointer()这样就不会删除上面第5条记录,只是今天刚写的,所以记下了,希望多多指点!