I would like to know how to count how many consecutive days up to today a user has been tagged as orange. I have the following
CREATE TABLE `survey_daily` (
`id` int(11) NOT NULL,
`user_id` varchar(30) NOT NULL,
`color` varchar(10) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `survey_daily` (`id`, `user_id`, `color`, `timestamp`) VALUES
(1, '3236', "ORANGE", '2020-05-12 02:40:59'),
(2, '3236', "WHITE", '2020-05-13 02:40:59'),
(3, '3236', "ORANGE", '2020-05-14 02:40:59'),
(4, '3236', "ORANGE", '2020-05-15 02:40:59'),
(5, '3237', "ORANGE", '2020-05-15 02:40:59'),
(6, '3237', "ORANGE", '2020-05-16 02:40:59'),
(7, '3236', "ORANGE", '2020-05-16 02:40:59');
Fiddle: http://sqlfiddle.com/#!9/40cb26/1.
Basically I have multiple users on a table and I would like to count how many consecutive days a user has been tagged as orange.
In my example, user id 3236 should have 3 consecutive days as orange while user 3237 should have 2 days tagged as orange until today. In case none of them has no record today it will return to 0.
Thank you
