GROUP BY · SUM
Count copies sold
Which game IDs have the most copies sold?
Compare with the solution
Ritmo de Neón leads with nine copies sold.
SELECT videojuego_id, SUM(unidades) AS unidades_vendidas FROM lineas_pedido GROUP BY videojuego_id ORDER BY unidades_vendidas DESC, videojuego_id ASC;
| videojuego_id | unidades_vendidas |
|---|---|
| 6 | 9 |
| 3 | 8 |
| 1 | 3 |
| 4 | 3 |
| 2 | 2 |
| 5 | 1 |
| 8 | 1 |