在postgresql
To accomplish this in Postgresql, two methods are commonly used:
Distinct On Operator
Postgresql provides the distinct on operator, which allows you to specify that only distinct values of a particular column(s) be returned.在这种情况下,操作员可以用如下:在(id)ID,date,entern_info上选择DISTITS DISTICT 来自the_table 按ID订购,日期desc; 此查询可确保仅返回每个唯一ID的最后一个实例,按日期下降顺序订购。此查询使用Row_number()函数将一个顺序编号分配给每个ID分区中的每个行。 Where子句过滤结果仅包括具有最高RN值的行(即每个ID的最后一行)。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3