看板 Database 關於我們 聯絡資訊
※ 引述《Schematic (小小寶的媽)》之銘言: : 內容/問題描述: : A表 : year id term status : 1 90 1 1 1 : 2 90 1 2 1 : 3 91 1 1 1 : 4 91 1 2 1 : 5 91 1 3 4 : 6 92 1 1 5 : 7 90 2 1 1 : 8 90 2 2 1 : 9 91 2 1 3 : 10 90 3 1 1 : 11 90 3 2 6 : B表 : year id type : 1 90 1 A : 2 90 2 B : 3 90 3 A : 希望的結果是要將A表中同一id下year最大且term最大的那一列join到B表 : year id type status : 1 90 1 A 5 (取A表的第6行的status值) : 2 90 2 B 3 (取A表的第9行) : 3 90 3 A 6 (取A表的第11行) : 不知道語法要怎麼下才會比較簡潔 : 謝謝 https://goo.gl/photos/nmatoCvvQgK9tVwF8 with tmp_A as( select row_number() over(partition by id order by [year] desc,[term] desc) as Num ,* From A) Select b.*,a.status from tmp_A a inner join B b on a.id=b.id where a.num=1 -- Sent from my Windows -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.136.240.135 ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1454555263.A.94B.html
Schematic: 非常謝謝您 02/04 11:21
atm: 請問這是什麼軟體的畫面呢 02/12 09:56