2017-04-19 44 views
0

我有一個表startdateenddate如何在postgresql的情況下得到一個新的列

其中開始日期大於endate我需要計算總天數爲30否則(enddate - startdate)+1 ...我如何爲它創建一個case語句。

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 
+0

你有沒有從表中的樣本,你希望有結果的一個例子嗎? – mongotop

+0

'當'startdate> enddate''無效時。 ''startdate> enddate''是一個字符串常量,但'when'子句需要一個布爾值。你需要使用'when startdate> enddate'(沒有單引號) –

回答

0
Select case when table1.startdate > table1.enddate then 30 
else table1.enddate - table1.startdate + 1 
end 
as td 
from table1 
相關問題