如图 我要查出3,4两条数据 身份证号相同,CPHM不同,怎么查询?怎么写着个语句啊 ,大神们求救啊,虽然分少了,但是我没分了,,,谢谢大神,感激不尽!
------解决思路----------------------
select * from 表 where (身份证号,CPHM,rowid) in (
select 身份证号,CPHM,min(rowid) from 表 group by 身份证号,CPHM
)
试试行不行
------解决思路----------------------
select dsrsfzh,count(distinct cphm) cp from yourTable group by dsrsfzh having count(distinct cphm)>1;
------解决思路----------------------
干嘛写那么复杂,同一张表关联不就可以了嘛
select * from table a,table b where a.dsrsfzh = b.dsrsfzh and a.cphm <> b.cphm ;
------解决思路----------------------
select * from yourTable where dsrsfzh in (
select dsrsfzh from yourTable group by dsrsfzh having count(distinct cphm)>1);
------解决思路----------------------
SELECT DSRSFZH, XM, JF, CPHM, CLZL, FZJG
FROM (SELECT DSRSFZH,
XM,
JF,
CPHM,
CLZL,
FZJG,
LAG(CPHM, 1, CPHM) OVER(PARTITION BY DSRSFZH ORDER BY CPHM) AS LG,
LEAD(CPHM, 1, CPHM) OVER(PARTITION BY DSRSFZH ORDER BY CPHM) AS M
FROM DS)
WHERE M != CPHM
OR CPHM != LG
------解决思路----------------------
select *
from table_name
where dsrsfzh in (select dsrsfzh
from table_name
group by dsrsfzh
having count(distinct cphm) > 1)
order by dsrsfzh;