例如
product_id | costhead_id | date
1020209 | 1000105 | 2020-04-01 08:58:15
1020209 | 1000182 | 2021-11-24 11:27:40
1020209 | 1000183 | 2021-12-19 16:19:55
1020210 | 1000105 | 2020-04-01 08:58:15
1020210 | 1000182 | 2021-11-24 11:27:40
1020210 | 1000183 | 2021-12-20 16:19:55
我需要一個product_id具有最大值的唯一值date。所需值如下
product_id | costhead_id | date
1020209 | 1000183 | 2021-12-19 16:19:55
1020210 | 1000183 | 2021-12-20 16:19:55
uj5u.com熱心網友回復:
您可以使用distinct on:
select distinct on(product_id) *
from table_name
order by product_id, date desc
小提琴
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/432616.html
標籤:sql PostgreSQL 最大限度
