日期:2014-05-17 浏览次数:20750 次
with temp as( select '001' id, 'BJ' city from dual union all select '001' id, 'SH' city from dual union all select '002' id, 'BJ' city from dual union all select '002' id, 'BJ' city from dual) SELECT id, city FROM temp WHERE id IN (SELECT id FROM (SELECT DISTINCT id, city FROM temp) GROUP BY id HAVING COUNT(1) > 1);
------解决方案--------------------
select id,city,row_number()over(parition by city order by id) row_num
from a
where row_num >1;
------解决方案--------------------
--5楼这个不对,改一下 with temp as( select '001' id, 'BJ' city from dual union all select '001' id, 'SH' city from dual union all select '002' id, 'BJ' city from dual union all select '002' id, 'BJ' city from dual union all select '003' id, 'BJ' city from dual) SELECT * FROM temp a WHERE (SELECT COUNT(1) FROM temp b WHERE b.id = a.id AND b.city <> a.city) > 0;
------解决方案--------------------
我只是来接分的~!
------解决方案--------------------
select id,city from 表A
where id in (select id from 表A group by id,city having count(1)=1);