I have two tables:
TotalTimeTable
(date date,time time)
FinalListA
(date date, time time, A int, B int)
I am running the following query:
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
Is there a way to pull out A and B from FinalListA where time = "max(t2.time)" in the same query?
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
The expected result is:
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
The time is from TotalTimeTable FinalListA.time don't have to be in the result.