在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