image.png

image.png

image.png

매출이 높은대로 출력

SELECT
product,
SUM(quantity * price) AS total_revenue,
COUNT(*) AS total_orders
FROM sales
GROUP BY product
ORDER BY total_revenue DESC;

월별 매출 집계

SELECT 
    SUBSTR(order_date, 1, 7) AS order_month,
    SUM(quantity * price) AS monthly_revenue
FROM sales
WHERE order_date IS NOT NULL
GROUP BY SUBSTR(order_date, 1, 7)
ORDER BY order_month ASC;

특정 기간 필터링

SELECT *
FROM sales
WHERE DATE_PARSE(order_date, '%Y-%m-%d') 
      BETWEEN DATE '2024-01-01' AND DATE '2024-01-31';