accident表不重复的:
select section,seqno from accident group by section,seqno having count(1) = 1human表不重复的:
select section,seqno from human group by section,seqno having count(1) = 1如果是查重复的就只要把having count(1) = 1改成having count(1) > 1 就好了
select section,seqno from accident group by section,seqno having count(1) = 1human表不重复的:
select section,seqno from human group by section,seqno having count(1) = 1如果是查重复的就只要把having count(1) = 1改成having count(1) > 1 就好了
select section,seqno,sno from human group by section,seqno,sno having count(1) = 1
1、对于accident表,select distinct section,seqno from accident能不能实现你说的效果?
2、我是想查不重复的记录的“条数”,不知道改怎么查
此句查询的是accident表中section,seqno 组合去除重复后的结果集,就是如果section,seqno 的组合有重复的,那么在查询出来的结果集中只会显示一次。如:
section seqno
---- ---
A B
A C
A C
A D那么查询的结果将会是:
section seqno
---- ---
A B
A C
A D
( select section,seqno
from accident
group by section,seqno
having count(1) = 1
) A; select count(1) from
( select section,seqno,sno
from human
group by section,seqno,sno
having count(1) = 1
) A;
如果我导出现在有重复数据的数据为文本文件,再删除里面的数据,应该就可以加上c2的主键了吧,加上之后再导入,是不是重复的数据就被删除了(重复的数据只剩下一条记录)。
select count(*)
from accident
group by section , seqno
having count(*) =1
如果我导出现在有重复数据的数据为文本文件,再删除里面的数据,应该就可以加上c2的主键了吧,加上之后再导入,是不是重复的数据就被删除了(重复的数据只剩下一条记录)。
====================================
可以的,但如果你并不需要手工决定重复的数据中需要保留哪条数据的话,可以有更简单的方法删除重复的数据:
Delete from human
where rowid not in (select max(rowid) //保留rowid最大的
from human
group by section,seqno,sno
having count(1) > 1
)
and rowid in
(select A.rowid
from human A join (select section,seqno,sno
from human
group by section,seqno,sno
having count(1) > 1
) B
on A.section=B.section and A.seqno=B.seqno and A.son=B.sno
)