PostgreSQL: Returning the most recent rows grouping by a foreign key column

后端 未结 2 1367
刺人心
刺人心 2021-01-23 10:54

I have a table that looks similar to this:

credit
+---------+----------------+-------------+--------------+-------------------------+
| id (PK) | person_id (FK)          


        
2条回答
  •  清酒与你
    2021-01-23 11:14

    Use distinct on:

    select distinct on (person_id) t.*
    from t
    order by person_id, date_time desc
    

提交回复
热议问题