我有两张桌子:
TotalTimeTable
(date date,time time)
FinalListA
(date date, time time, A int, B int)
我正在运行以下查询:
SELECT t1.date,
t1.time,
max(t2.time)
FROM TotalTimeTable t1,
FinalListA t2
WHERE t2.date=t1.date
AND t2.time <= t1.time
GROUP BY t1.date,
t1.time
ORDER BY t1.date,
t1.time
有没有办法从同一个查询中 time = "max(t2.time)" 的 FinalListA 中提取 A 和 B?
总时间表:
date time
2006-01-01 9:30:01
2006-01-01 9:30:02
2006-01-01 9:30:03
2006-01-01 9:30:04
2006-01-01 9:30:05
2006-01-01 9:30:06
最终名单A:
date time A B
2006-01-01 9:28:01 1 4
2006-01-01 9:30:02 2 3
2006-01-01 9:30:04 4 7
2006-01-01 9:30:07 6 4
2006-01-01 9:30:10 8 9
2006-01-01 9:30:11 1 2
预期结果是:
date time A B
2006-01-01 9:30:01 1 4
2006-01-01 9:30:02 2 3
2006-01-01 9:30:03 2 3
2006-01-01 9:30:04 4 7
2006-01-01 9:30:05 4 7
2006-01-01 9:30:06 4 7
时间来自 TotalTimeTable FinalListA.time 不必在结果中。