答案 0 :(得分:1)
使用类似的东西:
SELECT a.mydate, b.`close`
FROM (
SELECT max(t.`date`) AS mydate
FROM yourTable t
GROUP BY DATE_FORMAT(t.`date`,"%Y%m%d%H")
) a
LEFT JOIN yourTable b ON a.mydate = b.`date`
ORDER BY a.`date`;
答案 1 :(得分:0)
我改编了Bernd Buffen的回答。他的查询正确选择了每小时的最后一个时间戳,但是接近的值是错误的。我在下面的查询正确选择了接近的值。
SELECT table1.close
FROM `GBPUSD_minutes` table1
INNER JOIN(
SELECT max(`date`) as last FROM `GBPUSD_minutes` GROUP BY DATE_FORMAT(`date`,"%Y%m%d%H")
) table2
on table1.date = table2.last
WHERE `date` > '2010-01-01 00:00:00' AND `date` < '2010-01-30 00:00:00'
感谢Bernd Buffen给我
DATE_FORMAT(`date`,"%Y%m%d%H")
答案 2 :(得分:0)
试试这个。
SELECT t1.* FROM mytable t1
WHERE t1.`date` = (SELECT MAX(`date`) FROM mytable t2
WHERE DATE(t1.`date`) = DATE(t2.`date`) AND HOUR(t1.`date`) = HOUR(t2.`date`)
);