Получение наиболее частого значения в столбце для конкретного c человека - PullRequest
0 голосов
/ 11 июля 2020

Итак, у меня есть таблица, в которой я собираю данные каждого человека.

+--------+-------+--------+---------+----------------+
| player | kills | deaths | assists | champSelection |
+--------+-------+--------+---------+----------------+
| Bob    | 1     | 3      | 4       | Horse          |
+--------+-------+--------+---------+----------------+
| Bob    | 2     | 7      | 5       | Horse          |
+--------+-------+--------+---------+----------------+
| Jake   | 5     | 5      | 5       | Dog            |
+--------+-------+--------+---------+----------------+
| Marie  | 2     | 3      | 4       | Dog            |
+--------+-------+--------+---------+----------------+
| Marie  | 1     | 1      | 9       | Horse          |
+--------+-------+--------+---------+----------------+
| Marie  | 6     | 7      | 2       | Dog            |
+--------+-------+--------+---------+----------------+

И я запускаю

SELECT player, sum(kills), sum(deaths), sum(assists) 
FROM playerTable 
GROUP BY player 
ORDER BY player ASC;

Как мне добавить в свой запрос, где они чаще всего ChampSelection есть? Я пытаюсь отобразить свою таблицу как

+--------+-------+--------+---------+----------------+
| player | kills | deaths | assists | champSelection |
+--------+-------+--------+---------+----------------+
| Bob    | 3     | 10     | 9       | Horse          |
+--------+-------+--------+---------+----------------+
| Jake   | 5     | 5      | 5       | Dog            |
+--------+-------+--------+---------+----------------+
| Marie  | 9     | 11     | 15      | Dog            |
+--------+-------+--------+---------+----------------+

1 Ответ

1 голос
/ 13 июля 2020

Попробуйте следующее:

SELECT player, SUM(kills), SUM(deaths), SUM(assists), frequency
FROM
(
    SELECT player, SUM(kills) AS kills, SUM(deaths) AS deaths, SUM(assists) AS assists, champSelection, COUNT(*) AS frequency
    FROM playerTable
    GROUP BY player, champSelection
    ORDER BY frequency DESC
) AS inner_table
GROUP BY player
...