Volver
Ctrl+Space
◑
Copiar
Descargar
Restaurar
Ejecutar
Ctrl+Enter
-- Ejemplo 4: Reporte — Top clientes por gasto total -- ==================================================== SELECT c.nombre AS cliente, c.ciudad, COUNT(DISTINCT o.id) AS total_ordenes, SUM(d.cantidad) AS productos_comprados, ROUND(SUM(d.cantidad * d.precio_unitario), 2) AS gasto_total FROM clientes c JOIN ordenes o ON c.id = o.id_cliente JOIN detalle_ordenes d ON o.id = d.id_orden GROUP BY c.id, c.nombre, c.ciudad ORDER BY gasto_total DESC LIMIT 5;
RESULTADO
Escribí un query SQL y hacé clic en
Ejecutar
o presioná
Ctrl
+
Enter