dhS
dhS

Reputation: 3704

How to get a new column in the case in postgresql

I have a table with startdate and enddate.

where start date is greater than endate i need to calculate the total days as 30 otherwise (enddate - startdate)+1 ... how do i create a case statement for it.

Select case when 'startdate >  enddate' then 30
when 'startdate >  enddate' then (fine_fatturazione - startdate )+1
end
as td from table1


startdate   enddate
04-10-2015  04-12-2015
10-07-2015  09-08-2015
05-12-2015  04-01-2016
07-02-2016  04-01-2016

Upvotes: 0

Views: 938

Answers (1)

Vecchiasignora
Vecchiasignora

Reputation: 1315

Select case when table1.startdate >  table1.enddate then 30
else table1.enddate - table1.startdate + 1
end
as td 
from table1

Upvotes: 0

Related Questions