SQL
文章目录
清空表数据:truncate Table tablename
查重
查找表中多余的重复记录,重复记录时根据单个字段来判断:
SELECT * FROM RADA_CHN_DOR_L2_QC_F_TAB WHERE V_FILE_NAME IN (SELECT V_FILE_NAME FROM RADA_CHN_DOR_L2_QC_F_TAB GROUP BY V_FILE_NAME HAVING COUNT(V_FILE_NAME)>1)
删除表中多余的重复记录,重复记录时根据单个字段来判断,只留下id最小的记录
delete from RADA_CHN_DOR_L2_QC_F_TAB
where V_FILE_NAME in (select V_FILE_NAME from RADA_CHN_DOR_L2_QC_F_TAB group by V_FILE_NAME having count
(V_FILE_NAME) > 1)
and id not in (select min(id) from RADA_CHN_DOR_L2_QC_F_TAB group by V_FILE_NAME having count(V_FILE_NAME
)>1)
查找表中多余的重复记录,多个字段对比
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
删除表中多余的重复记录多个字段,直留下id最小的记录
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
查找表中多余的重复记录(多个字段),不包含id最小的记录;
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
查看某一项(Name)相同数据的所有数据:
select Name,Count(*) from tablename Group By Name Having Count(*) > 1;