2017-06-07 41 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;