Automatically beautify, validate, and safely minify complex SQL queries across 9 dialects.
Automatically formats in real time as you type or adjust options.
-- 카테고리별 완료 주문 매출 및 객단가 집계 SELECT c.category_name, p.product_id, p.product_name, COUNT(DISTINCT o.order_id) AS completed_orders, SUM(oi.quantity) AS total_units, SUM(oi.quantity * oi.unit_price) AS gross_revenue, ROUND(AVG(oi.quantity * oi.unit_price), 0) AS avg_item_revenue FROM products p INNER JOIN categories c ON p.category_id = c.category_id LEFT JOIN order_items oi ON p.product_id = oi.product_id LEFT JOIN orders o ON oi.order_id = o.order_id WHERE o.status = 'COMPLETED' AND o.created_at >= '2026-01-01 00:00:00' AND p.is_deleted = FALSE GROUP BY c.category_name, p.product_id, p.product_name HAVING SUM(oi.quantity * oi.unit_price) >= 1000000 ORDER BY gross_revenue DESC, completed_orders DESC LIMIT 30;