如上数据有什么方法挑选出,DXID,和DXLXID,对应多个COMPID的列,然后再挑选出对应了一个COMPID的列呢?
SELECT ROW_NUMBER() OVER(PARTITION BY dxid,dxlxid ORDER BY compid DESC) compid_count,
dxid,dxlxid,compid from mytest
这个可以出求出如下结果,可惜,怎么分离出来呢?
WITH A AS (SELECT ROW_NUMBER() OVER(PARTITION BY dxid, dxlxid ORDER BY compid DESC) AS compid_count,
dxid,
dxlxid,
compid
FROM mytest)
SELECT A.compid_count, A.dxid, A.dxlxid, A.compid
FROM A,
(SELECT compid_count, COUNT(*) AS num
FROM A
GROUP BY compid_count) B
WHERE A.compid_count = B.compid_count
AND B.num = 1;