0
在這一刻,我有以下行的值:如何查詢:agregate組由A列的每一列B值
構建此表:
CREATE TABLE `registros` (
`id_registro` int(11) NOT NULL,
`id_partida` int(11) NOT NULL,
`id_juego` int(11) NOT NULL,
`id_jugador` int(11) NOT NULL,
`score` float NOT NULL DEFAULT '0',
`fecha_creacion` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO `registros` (`id_registro`, `id_partida`, `id_juego`, `id_jugador`, `score`, `fecha_creacion`) VALUES
(1, 2, 2, 1, 300, '2017-02-27 22:14:50'),
(2, 2, 2, 2, 350, '2017-02-27 22:14:50'),
(3, 2, 2, 3, 365, '2017-02-27 22:14:50'),
(4, 2, 2, 4, 110, '2017-02-27 22:14:50'),
(5, 2, 2, 5, 90, '2017-02-27 22:14:50'),
(6, 2, 2, 6, 840, '2017-02-27 22:15:11'),
(7, 2, 2, 7, 500, '2017-02-27 22:15:11'),
(8, 2, 2, 1, 20, '2017-02-27 22:15:45'),
(9, 2, 2, 1, 610, '2017-02-27 22:15:45'),
(10, 2, 2, 2, 415, '2017-02-27 22:16:07'),
(11, 2, 2, 4, 220, '2017-02-27 22:16:07'),
(13, 3, 1, 1, -600, '2017-02-27 22:17:47'),
(14, 3, 1, 1, -550, '2017-02-27 22:17:47'),
(15, 3, 1, 2, -480, '2017-02-27 22:17:47'),
(16, 3, 1, 2, -700, '2017-02-27 22:17:47'),
(17, 3, 1, 9, -490, '2017-02-27 22:18:18'),
(21, 3, 1, 2, -700, '2017-02-27 22:18:18');
我需要通過id_jugador
與他的最好成績爲每id_partida
(遊戲大賽)(誰在比賽中發揮一定時期有不同的分數播放器),以得到一組。
我有一個「排行榜」每場比賽。這是我的SQL代碼吧:
SELECT registros.id_partida, registros.id_jugador,MAX(registros.score) as best_score
FROM registros
WHERE registros.id_partida = 2
GROUP BY registros.id_jugador
ORDER BY best_score DESC;
和執行結果:
但我想知道的所有比賽的所有級別和遊戲中的位置。不僅使用where子句與特定目標id_partida = 2
。究竟如下:
Mysql數據庫在這裏:http://pastebin.com/8eYuYzgV
謝謝大家。
我覺得以前沒有嘗試過很愚蠢......非常感謝。現在我需要獲得所有球員的位置欄 – SerCrAsH