Use Partition in SQL

后端 未结 1 1260
深忆病人
深忆病人 2021-01-26 03:31

I have a problem with a query. Here is the query.

SELECT UserID, MAX(UserName) as UserName, MAX(TransactionTime) as TransactionTime,         MAX(LastAction) as L         


        
相关标签:
1条回答
  • 2021-01-26 03:48

    A ranking function is probably what you are looking for:

    SELECT *
    FROM (
       SELECT UserID, UserName, LastAction, row_number() over(partition by UserId order by TransactionTime desc) RowNo
       FROM UserActivities 
       WHERE OrganizationID = 26465
    ) t
    where t.RowNo = 1
    
    0 讨论(0)
提交回复
热议问题