一、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;