I’m playing around with reporting and I would like to get the record for each date between dates.
I have the StartDate and EndDate on calendars and I can retrieve data between the two selected dates but I don’t know how the grab only the last record for each date.
Below is the query I have so far.
SELECT transaction.t_stamp,
transaction.AveAmps,
transaction.Random
FROM transaction
WHERE transaction.t_stamp >= ? AND transaction.t_stamp <= ?
ORDER BY transaction.t_stamp
I’m testing at home on 8.0.10 but have an older version at work ~7.something
Ok, that’s different to what I orginally thought you were after.
As jonathan suggests, maybe something like this:
SELECT
T.t_stamp,
T.AveAmps,
T.Random
FROM transaction T
INNER JOIN
(
SELECT MAX(t_stamp) max_time
FROM transaction
GROUP BY date(t_stamp)
) AS D
ON T.t_stamp = D.max_time
SELECT *
FROM test
WHERE t_stamp IN
(SELECT MAX(t_stamp)
FROM test
GROUP BY FORMAT(t_stamp, 'yyyy-MM-dd'))
Or, untested:
SELECT transaction.t_stamp,
transaction.AveAmps,
transaction.Random
FROM transaction
WHERE t_stamp IN
(SELECT MAX(t_stamp)
FROM transaction
WHERE t_stamp >= ? AND t_stamp <= ?
GROUP BY FORMAT(t_stamp, 'yyyy-MM-dd')
)
ORDER BY transaction.t_stamp
David’s code gets me what I was originally looking for. Now that I’m at work, going to try and add more improvements.
Thanks All and I’m sure I’ll return.