第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

oracle 指定字段排序并去重?

oracle 指定字段排序并去重?

GCT1015 2018-07-22 14:18:05
有l(wèi)ogs表的結構為uesrid | status    |    order111    | 5         |    7111    | 0         |    9111    | 1         |    8222    | 3         |    3222    | 1         |    2222    | 2         |    4333    | 3         |    10請問如何先以order desc排序,并通過userid去重,同時獲取userid,status,order的值。想要的結果為uesrid | status    |    order111    | 0         |    9222    | 2         |    4333    | 3         |    10在mysql下,可以通過以下SQL獲得。SELECT * FROM (SELECT * FROM `logs` ORDER BY `order` DESC) AS a GROUP BY a.userid;但是oracle這么寫語法就報錯,請問oracle該如何實現(xiàn)?
查看完整描述

3 回答

?
慕娘9325324

TA貢獻1783條經(jīng)驗 獲得超4個贊

WITH temp as

    (

    select '111' as userid,'5' as status,'7' as ord from dual

    union all

    select '111' as userid,'0' as status,'9' as ord from dual

    union all

    select '111' as userid,'1' as status,'8' as ord from dual

    union all

    select '222' as userid,'3' as status,'3' as ord from dual

    union all

    select '222' as userid,'1' as status,'2' as ord from dual

    union all

    select '222' as userid,'2' as status,'4' as ord from dual

    union all

    select '333' as userid,'3' as status,'10' as ord from dual

    )

select userid,status,ord from (    

select userid,status,ord,row_number() over(partition by userid order by ord desc)  rn 

from temp

)

where rn=1

;


查看完整回答
反對 回復 2018-07-25
?
撒科打諢

TA貢獻1934條經(jīng)驗 獲得超2個贊

用開窗函數(shù)就可以呀:

https://img1.sycdn.imooc.com//5b587ade0001f46603160191.jpg

https://img1.sycdn.imooc.com//5b587adf000105ba07840379.jpg


查看完整回答
反對 回復 2018-07-25
  • 3 回答
  • 0 關注
  • 1796 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號