这个查询给出了重复但是我很难理解为什么?我在trading.delayed中每个id都有很多行,但只有一个具有完全相同的时间戳
有人能解释我的错过吗?
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 :(得分: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;