2020年6月9日 星期二

Table 分組後取最大的資料列


1.
  Select A.* 
  From [Table1] as A
  Inner Join (
              Select [Field01], Max([Score]) Score
              From [Table1]
              Group By [Field01) as B on A.[Field01]=B.[Field01] and A.[Score]=B.[Score] 
  Order By A.[Field01]

2.
  Select *
  From (
    Select ROW_NUMBER() OVER(PARTITION BY [Field01] ORDER BY [Score] DESC) as rowid, *
    FROM [Table1]
  )
  Where rowid=1

沒有留言:

張貼留言