一、SQL删除某些字段重复的记录(只保留一条)
1.查询出来重复的记录数:
select t.* from test2 t inner join(select name,age from test2 s group by name,age having count(*)>1)b
on t.name=b.name and t.age=b.age
select t.name,t.age,count(*) as num1 from test2 t group by name,age having count(*)>1
2.删除重复的记录数(只保留一条):
delete from test2 t where t.id not in (select max(id) from test2 s group by name,age)
二、一个表中有一个id字段,选出重复大于三的字段:
select id,count(name) from test t group by id having count(name)>=3
两个日期间的天数 :
select floor(sysdate - to_date('20020405','yyyymmdd')) from dual;