select *from (SELECT C.*,
ROW_NUMBER() OVER(PARTITION BY C.B_SNO ORDER BY C.B_SNO DESC) AS BSNOFROM 表 C
where C.NODE_KEY = 'mobileCorrTask'
order by OPER_TIME desc)
WHERE BSNO = 1
根据B_SNO 字段去重复
主要运用了
ROW_NUMBER() OVER(PARTITION BY ‘ 字段1‘ ORDER BY ‘字段2‘DESC)
这个函数可以百度下
SQL> SELECT ID,NAME,DATE1,ROW_NUMBER() OVER(partition by ID order by DATE1 desc) as RN FROM T1;
ID NAME DATE1 RN
---------- ------------------------------ ------------------ ----------
101 ccc 11-SEP-13 1
101 bbb 10-SEP-13 2
101 aaa 09-SEP-13 3
102 eee 11-SEP-13 1
102 ddd 08-SEP-13 2
这是查出所有值 加上条件RN=1的则为根据id去重复后的
SQL> SELECT ID,NAME,DATE1 FROM (SELECT ID,NAME,DATE1,ROW_NUMBER() OVER(partition by ID order by DATE1 desc) as RN FROM T1)T WHERE T.RN=1;
ID NAME DATE1
---------- ------------------------------ ------------------
101 ccc 11-SEP-13
102 eee 11-SEP-13