Trying to utilize MySQL Date and Time functions. Currently I have a table that shows a mailman's routes for the past 5 days. These values are stored as a time stamp in my database. I want all of the Street Addresses this mailman has visited in the past 3 days.
So far, I can do this following query:
"SELECT RouteEndTime
FROM Mailman GROUP BY RouteEndTime
HAVING DATEDIFF(MAX(RouteEndTime), RouteEndTime) <= 3;"
but I only get back all of the RouteEnd values for all 15 rows
I'm looking at this list of resources:
https://www.w3schools.com/sql/sql_ref_mysql.asp
Under MySQL Date Functions, but there is no function that does what I need it to do.
Is there a function that I can use to get all the street addresses he visited in the most recent 3 days (starting from the most recent date in my db) The answer I'm looking for is basically all the street address names from January 5th, 4th and 3rd.
MailManID | Street Address | RouteStartTime | RouteEndTime
54 | 'Apple St' | '2018-01-05 09:00:00' | '2018-01-05 09:05:00'
54 | 'Bat St' | '2018-01-05 09:30:00' | '2018-01-05 09:35:00'
54 | 'Cat St' | '2018-01-05 09:45:00' | '2018-01-05 09:50:00'
54 | 'Kite St' | '2018-01-04 09:00:00' | '2018-01-04 09:05:00'
54 | 'Lemon St' | '2018-01-04 09:30:00' | '2018-01-04 09:35:00'
54 | 'Muppet St' | '2018-01-04 09:45:00' | '2018-01-04 09:50:00'
54 | 'Luke St' | '2018-01-03 09:00:00' | '2018-01-03 09:05:00'
54 | 'Ben St' | '2018-01-03 09:30:00' | '2018-01-03 09:35:00'
54 | 'Cow St' | '2018-01-03 09:45:00' | '2018-01-03 09:50:00'
54 | 'Hello St' | '2018-01-02 09:00:00' | '2018-01-02 09:05:00'
54 | 'Igloo St' | '2018-01-02 09:30:00' | '2018-01-02 09:35:00'
54 | 'Jump St' | '2018-01-02 09:45:00' | '2018-01-02 09:50:00'
54 | 'Yellow St' | '2018-01-01 09:00:00' | '2018-01-01 09:05:00'
54 | 'Blue St' | '2018-01-01 09:30:00' | '2018-01-01 09:35:00'
54 | 'Red St' | '2018-01-01 09:45:00' | '2018-01-01 09:50:00'
I want to return something like:
'Apple St' '2018-01-05 09:00:00' '2018-01-05 09:05:00'
'Bat St' '2018-01-05 09:30:00' '2018-01-05 09:35:00'
'Cat St''2018-01-05 09:45:00' '2018-01-05 09:50:00'
'Kite St''2018-01-04 09:00:00' '2018-01-04 09:05:00'
'Lemon St''2018-01-04 09:30:00' '2018-01-04 09:35:00'
'Muppet St''2018-01-04 09:45:00' '2018-01-04 09:50:00'
'Luke St''2018-01-03 09:00:00' '2018-01-03 09:05:00'
'Ben St''2018-01-03 09:30:00' '2018-01-03 09:35:00'
'Cow St''2018-01-03 09:45:00' '2018-01-03 09:50:00'