MySQL 5.5 – in my table logs, how do I sum the values of the n most recent entries per user_id, for all user_ids?
CREATE TABLE `logs` (
`id` INT NOT NULL ,
`user_id` INT NULL ,
`value` INT NULL ,
`date_created` DATETIME NULL ,
PRIMARY KEY (`id`) );
Try this query:
Please note, I have not tested it so it may need a little tweaking.