×

sql · level 2 · unit 1 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Group by two columns for one row per .

GROUP BY player gives one row per player. GROUP BY player, game goes finer: one group for every combination of player and game in the table, like Mia with darts and Mia with bowling.

One rule keeps reports honest. Every plain column in SELECT must also be in GROUP BY. Everything else must sit inside an aggregate.

Break the rule and SQLite does not complain. It quietly takes the value from one row of the group, which is often the wrong one.

SELECT player, game, COUNT(*) AS rounds, SUM(points) AS total
FROM rounds
GROUP BY player, game
ORDER BY player, game;

ORDER BY player, game sorts by player first, then by game within each player.