我有一个MySQL表,它基本上存储一个点的列表引用了该点的玩家ID。MYSQL - 计数连续相同的值
我的设置是:
CREATE TABLE `points` (
`id` int(10) unsigned NOT NULL,
`player_id` int(10) unsigned NOT NULL,
`game_id` int(10) unsigned NOT NULL,
`score` int(11) NOT NULL,
`isScore` tinyint(1) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
);
INSERT INTO `points` (`id`, `player_id`, `game_id`,
`score`, `isScore`, `created_at`, `updated_at`)
VALUES
(16, 11, 60, 4, 0, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(17, 11, 60, 5, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(18, 12, 60, 6, 0, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(19, 12, 60, 7, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(20, 12, 60, 8, 0, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(21, 12, 60, 9, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(22, 8, 60, 10, 0, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(23, 8, 60, 11, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(24, 12, 60, 12, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(25, 12, 60, 13, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(26, 5, 60, 14, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(27, 12, 60, 15, 0, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(28, 12, 60, 16, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(29, 10, 60, 17, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(30, 10, 60, 18, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39');
下面是在此设置一个SQLfiddle:http://sqlfiddle.com/#!9/f6ca9f8
我想为每个选手的选手取得最大的连续点的数量。
所以在sqlfiddle结果会是这样的:
+-----------+------------------------+
| player_id | max_consegutive_points |
+-----------+------------------------+
| 12 | 4 |
| 8 | 2 |
| 5 | 1 |
| 10 | 2 |
+-----------+------------------------+
下一次加你在这里设置。有时候这些支持网站(如sqlfiddle)已经不存在了,在这种情况下,你的问题不会有数据。 –
请解释你的输出 – GurV