-- Ejecutar en una base vacía de SQLite. -- Cada fila ya está normalizada y representa una línea de movimiento. CREATE TABLE movimientos ( sistema TEXT NOT NULL, id_movimiento TEXT NOT NULL, fecha TEXT NOT NULL, tienda TEXT NOT NULL, producto TEXT NOT NULL, unidades INTEGER NOT NULL CHECK (unidades <> 0), precio_centimos INTEGER NOT NULL CHECK (precio_centimos >= 0), moneda TEXT NOT NULL, PRIMARY KEY (sistema, id_movimiento) ); INSERT INTO movimientos VALUES ('TPV-N', 'N1', '2026-01-10', 'Norte', 'A', 2, 1000, 'EUR'), ('TPV-N', 'N2', '2026-01-10', 'Norte', 'B', 1, 4000, 'EUR'), ('TPV-S', 'S1', '2026-01-10', 'Sur', 'A', 3, 1000, 'EUR'), ('TPV-S', 'S2', '2026-01-10', 'Sur', 'B', 2, 4000, 'EUR'), ('TPV-N', 'N3', '2026-01-11', 'Norte', 'C', 1, 2000, 'EUR'), ('TPV-S', 'S3', '2026-01-11', 'Sur', 'B', -1, 4000, 'EUR'); SELECT tienda, SUM(unidades) AS unidades_netas, SUM(unidades * precio_centimos) / 100.0 AS importe_eur FROM movimientos WHERE moneda = 'EUR' GROUP BY tienda ORDER BY tienda;