我有兩個表:使用max函數
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
有沒有辦法從FinalListA拔出A和B,時間=「MAX( t2.time)「在同一個查詢中?
TotalTimeTable:
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
FinalListA:
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不必在結果。
請提供示例行。 –