例如:
表格数据如下所示。我需要查询结果,如下所示。帮帮我们...... 数据
Data
date time temperature updated_time
01-04-2015 0:00 30 1:00:00 AM
01-04-2015 1:00 31
01-04-2015 2:00 32
01-04-2015 3:00 30
01-04-2015 4:00 31
. . . .
. . . .
. . . .
01-04-2015 24:00:00 30 1:00:00 AM
01-04-2015 3:00 30 3:00:00 AM
01-04-2015 4:00 31 3:00:00 AM
01-04-2015 5:00 32 3:00:00 AM
01-04-2015 6:00 30 3:00:00 AM
. . . .
. . . .
. . . .
01-04-2015 24:00:00 30 3:00:00 AM
01-04-2015 6:00 30 6:00:00 AM
01-04-2015 7:00 31 6:00:00 AM
01-04-2015 8:00 32 6:00:00 AM
01-04-2015 9:00 30 6:00:00 AM
. . . .
. . . .
. . . .
01-04-2015 24:00:00 30 6:00:00 AM
结果将是
date time temperature updated_time
01-04-2015 0:00 30 1:00:00 AM
01-04-2015 1:00 31 1:00:00 AM
01-04-2015 2:00 32 1:00:00 AM
01-04-2015 3:00 30 3:00:00 AM
01-04-2015 4:00 30 3:00:00 AM
01-04-2015 5:00 31 3:00:00 AM
01-04-2015 6:00 32 6:00:00 AM
01-04-2015 7:00 30 6:00:00 AM
. . . .
. . . .
. . . .
01-04-2015 21:00 30 9:00:00 PM
01-04-2015 22:00 30 9:00:00 PM
01-04-2015 23:00 30 9:00:00 PM
答案 0 :(得分:0)
假设您的数据表看起来像
CREATE TABLE data (
date date,
time time,
temperature decimal,
updated_time time
);
以下应该可以解决问题:
SELECT date, time, temperature, updated_time
FROM data d1
WHERE d1.updated_time=
(SELECT MAX(updated_time) FROM data d2 WHERE d2.date=d1.date and d2.time=d1.time)
ORDER BY date, time;