表的结构是这样的
typ doc seq
1 12 1
1 12 2
2 13 1
2 13 2
要根绝doc的值,判断对应的typ是否相同,即对于doc是12,他们的typ是否相同,我只会一个比较笨的方法,就是取出所有的doc号,在doc相同的判断,可是我觉得这样效率太低了。有更简单的方法吗?多谢
---------------------------------------------------------------
select doc,typ from tablename
group by doc,typ having count(*)>1
---------------------------------------------------------------
select * from tablename a
where exists (
select * from tablename
where doc=a.doc
and typ<>a.typ
)