I have a excel where i read a dbf file with a select. I want to select the last datetime from each code_id.
Code_id daytime
1 12-01-2016 9:58:12
1 12-01-2016 10:01:12
2 12-01-2016 10:54:01
2 12-01-2016 11:01:01
A result i get:
1 12-01-2016 9:58:12
2 12-01-2016 11:01:01
I want result:
1 12-01-2016 10:01:12
2 12-01-2016 11:01:01
It seems there is a problem when the time go from 09 to 10, because if time go from 10 to 11 or 11 to 12 i get the last time, but when the time go from 9 to 10 it get the last time of 9 instead of time 10
Is there something wrong in my code?
SELECT b.code_id, COUNT(*) AS cnt, b.name,
b.type, a.tp
FROM " & Filename & " b
INNER JOIN (select code_id, MAX(daytime) AS tp
FROM " & Filename & " group by code_id) a
ON a.code_id = b.code_id
where DateValue(daytime) <= Date()
group by b.code_id, b.name,
b.type, a.tp
order by b.code_id