basic table is similar to:
mysqlTable:
visitorID ,park ,DateTimeStamp
8369 ,Birmingham ,12/27/2018 03:26:38 PM
8369 ,Birmingham ,12/28/2018 11:27:32 AM
8828 ,Central ,01/02/2019 10:01
8828 ,Central ,01/04/2019 9:50
8825 ,Central ,12/21/2018 09:47:27 AM
8821 ,Central ,12/26/2018 10:11:40 AM
8821 ,Central ,02/03/2019 10:00:59 AM
8821 ,Central ,01/02/2019 10:04
88281 ,Central ,01/04/2019 9:53
From this table i'm creating a new one where i'm counting visitor's ID in a specific park, then grouping the visits by the visitorID and the date of the visit in a specific period of time.
mysql query:
SELECT COUNT(*)AS visits,dateTimeStamp,visitorID
FROM parkVisits
WHERE
dateTimeStamp BETWEEN '2019-01-01 00:00:01' AND '2019-01-04 23:59:59'
AND park ='Central'
GROUP BY visitorID, CAST(dateTimeStamp AS DATE);
my result:
mysql table:
visits ,dateTimeStamp ,visitorID
2 ,01/02/2019 10:01 ,8828
1 ,01/02/2019 10:04 ,8821
1 ,01/04/2019 9:53 ,88281
I would like to have a column where a Boolean indicates if the visitor has visited anytime before the specified date of it's row. I was thinking about comparing the earliest dateTimeStamp on table to the earliest given date, but a situation can occur where the first visit and the returning visit occurred during the given period.
expected:
mysql table:
visits ,dateTimeStamp ,visitorID ,returningVisitor
2 ,01/02/2019 10:01, 8828 ,TRUE
1 ,01/02/2019 10:04, 8821 ,FALSE
1 ,01/04/2019 9:53, 88281 ,FALSE
EDIT:
i'm using MySQL 5.6.40