看板 Database 關於我們 聯絡資訊
方法 1: select t1.A,t1.B,t1.C from table t1 inner join ( select A,max(C) as C from table group by A ) t2 on t1.A = t2.A and t1.C = t2.C 方法 2: select A,B,C from ( select A,B,C, rank() over (partition by A order by C desc) as num from table ) t1 where num = 1 方法 3: select A,B,C from table t1 where C = ( select max(C) from table where A = t1.A ) ※ 引述《oherman (qq)》之銘言: : 資料庫名稱:sql server 2014 : 資料庫版本:2016 : 內容/問題描述: : 我的資料結構如下 : A欄 B欄 C欄 : ======================= : A 10 20180702 : A 10 20180801 : A 20 20180703 : B 20 20180706 : B 20 20180710 : B 20 20180711 : 我只要顯示 : A欄 B欄 C欄 : ======================= : A 10 20180801 : B 20 20180711 : A欄group後的c欄最大值的那筆row data : 請問要如何下語法? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.168.23.228 ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1536303684.A.DCA.html
oherman: 感謝,可以 09/10 17:45