GROUP BY · revenue

Compare monthly revenue

For each month, how much revenue did the store earn, how many copies did it sell, and how many orders did customers place?

SQLite
RESULTSReady to run
Compare with the solution

Revenue totals €320 in October and €380 in November. The sample contains four orders in each month.

SELECT strftime('%Y-%m', p.fecha) AS mes,
       COUNT(DISTINCT p.id) AS numero_pedidos,
       SUM(lp.unidades) AS unidades_vendidas,
       SUM(lp.unidades * lp.precio_unitario_euros) AS facturacion_euros
FROM pedidos AS p
JOIN lineas_pedido AS lp ON lp.pedido_id = p.id
GROUP BY strftime('%Y-%m', p.fecha)
ORDER BY mes ASC;
mesnumero_pedidosunidades_vendidasfacturacion_euros
2026-10413320
2026-11414380