Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 仅选择唯一ID的最近日期_Postgresql - Fatal编程技术网

Postgresql 仅选择唯一ID的最近日期

Postgresql 仅选择唯一ID的最近日期,postgresql,Postgresql,这应该是一个简单的问题来解决,但由于某种原因,我无法理解如何有效地做到这一点 假设我有一个表(postgres),看起来像这样: 身份证件 日期 价值 1. 2021-04-01 1. 1. 2021-04-03 10 1. 2021-04-04 8. 1. 2021-04-05 3. 1. 2021-04-08 5. 2. 2021-04-04 3. 2. 2021-04-05 5. 2. 2021-04-07 5. 2. 2021-04-10 9 2. 2021-04-12 11 您可以使用

这应该是一个简单的问题来解决,但由于某种原因,我无法理解如何有效地做到这一点

假设我有一个表(postgres),看起来像这样:

身份证件 日期 价值 1. 2021-04-01 1. 1. 2021-04-03 10 1. 2021-04-04 8. 1. 2021-04-05 3. 1. 2021-04-08 5. 2. 2021-04-04 3. 2. 2021-04-05 5. 2. 2021-04-07 5. 2. 2021-04-10 9 2. 2021-04-12 11
您可以使用窗口功能:

select * from 
  ( 
    select * , row_number() over (partition by id order by date desc) rn 
    from yourtable
  ) t
where rn = 1

您可以使用窗口功能:

select * from 
  ( 
    select * , row_number() over (partition by id order by date desc) rn 
    from yourtable
  ) t
where rn = 1