How to select last record from each day with MySQL
SELECT t1.* FROM personal_measurements t1
JOIN (SELECT DATE(created_at) date_date, user_id, MAX(created_at) max_date
FROM personal_measurements
GROUP BY date_date, user_id
) t2
ON t1.created_at = t2.max_date AND t1.user_id = t2.user_id;
JOIN (SELECT DATE(created_at) date_date, user_id, MAX(created_at) max_date
FROM personal_measurements
GROUP BY date_date, user_id
) t2
ON t1.created_at = t2.max_date AND t1.user_id = t2.user_id;
Comments
Post a Comment