Skip to content
Advertisement

Minimum of Days Difference between Dates and Update PostgreSQL

I have a situation like, I need to find out which record is having minimum difference of days between atleast 2 dates. Like –

Table Data is like

Table Data

Input Parameter : [aDate = 12-Nov-2020, Infold = 2]

Result should be:

Result updated

Need to find the date difference between the input dates and existing dates, find the record which is having minimum days gap.

I am trying in this way:

I just need to identify that particular record, kindly advise.

Advertisement

Answer

You can use order by and limit to identify the “closest” record to a given date:

If you want an update statement:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement