1

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

SELECT UserID, MAX(UserName) as UserName, MAX(TransactionTime) as TransactionTime,         MAX(LastAction) as LastAction 
FROM UserActivities 
WHERE OrganizationID = 26465
GROUP BY UserID

There are so many records for particular user at different TransactionTime. I want to take LastAction along with other records. How can I do it? Is SQL partition will work here?

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.