2017-08-03 21 views
-1

嗨,我在Oracle中相同的查詢我想在postgres中隱藏間隔到十進制,需要這個結果嗎?

select (TRUNC(b.pub_ts, 'MI') - DATE '1970-01-01')* 24 * 60 * 60, 
      TRUNC(b.pub_ts, 'MI') - DATE '1970-01-01' 
       from abctable b where b.blurb_id=344143 

查詢Oracle中的輸出是這

enter image description here

,我已經在Postgres的轉換查詢,我想同樣的結果,我怎麼可以得到,我已經創建了查詢postgres,但它是給的間隔不是十進制輸出像甲骨文

select (date_trunc('minute', b.pub_ts) - DATE '1970-01-01')* 24 * 60 * 60, 
           date_trunc('minute', b.pub_ts) - DATE '1970-01-01' 
    FROM abc b WHERE b.blurb_id=344143; 

enter image description here

我已經嘗試了很多解決方案。你能幫我嗎。

+0

沒有這不會給我想要的輸出。 –

回答

3

我覺得are是正確的,我認爲這是How do I convert an interval into a number of hours with postgres?

重複如果選中接受的答案,在下面的例子是不同的嘛,我加的24

SELECT EXTRACT(epoch FROM INTERVAL '1499990400 days 1206720:00:00')/24/60/60, 
     EXTRACT(epoch FROM INTERVAL '17361 days 13:58:00')/24/60/60; 

回報

1500040680和17361.581944444442

這正是你們灣值噸。

您的查詢應該沿着這行看起來:

SELECT 
    extract(epoch FROM date_trunc('minute', b.pub_ts) - DATE '1970-01-01'), 
    extract(epoch FROM date_trunc('minute', b.pub_ts) - DATE '1970-01-01')/86400 
FROM abc b WHERE b.blurb_id=344143; 
+0

這是完美的解決方案。 –

相關問題