user1538020 user1538020 - 11 months ago 38
SQL Question

Max of a Date field into another field in Postgresql

I have a postgresql table wherein I have few fields such as id and date. I need to find the max date for that id and show the same into a new field for all the ids. SQLFiddle site was not responding so I have an example in the excel. Here is the screenshot of the data and the output for the table.

enter image description here


You could use the windowing variant of max:

SELECT id, date, MAX(date) OVER (PARTITION BY id)
FROM   mytable