2017-06-07 63 views
0

此查詢提供重複,但我很努力地明白爲什麼?我確實在trading.delayed中有許多行每個id,但只有一個具有完全相同的時間戳postgres按日期(長)按時區選擇

有人能解釋我缺少什麼嗎?

 SELECT t1.contract,t1.date FROM trading.delayed AS t1, 
(SELECT contract, max(date) AS date FROM trading.delayed GROUP BY contract) AS t2 
WHERE t1.date =t2.date order BY contract DESC; 

結果:合同,日期

32;"2017-06-07 02:04:11.797+07" 
32;"2017-06-07 02:04:14.489+07" 
31;"2017-06-07 02:04:12.04+07" 
30;"2017-06-07 02:03:54.182+07" 
30;"2017-06-07 00:20:27.812+07" 
30;"2017-06-07 02:03:51.177+07" 
29;"2017-06-07 00:20:27.812+07" 
28;"2017-06-07 01:45:53.129+07" 
27;"2017-06-07 01:58:02.974+07" 
+0

上運行ID的確切查詢(而不是合同號)的作品,雖然。看起來像一個日期的行爲,順便提一下,這是一個時間戳。 – matel

回答

0

這不是一個答案,但這個版本的作品

SELECT t1.contract,close 
FROM trading.delayed AS t1, 
    ( 
     SELECT max(id) as id, 
      contract, 
      max(date) AS date 
     FROM trading.delayed 
     GROUP BY contract 
    ) AS t2 
WHERE t1.id =t2.id 
order by contract desc;