How to make a SQL query for last transaction of every account?

前端 未结 4 1006
心在旅途
心在旅途 2020-12-28 08:59

Say I have a table \"transactions\" that has columns \"acct_id\" \"trans_date\" and \"trans_type\" and I want to filter this table so that I have just the last transaction f

4条回答
  •  -上瘾入骨i
    2020-12-28 09:12

    This works on SQL Server...

    SELECT acct_id, trans_date, trans_type
    FROM transactions a
    WHERE trans_date = (
       SELECT MAX( trans_date )
       FROM transactions b
       WHERE a.acct_id = b.acct_id
    )
    

提交回复
热议问题