SQL, 이 정도는 알아야지 😎
조회 성능 개선하기 미션을 진행할 때 최소한으로 필요한 SQL 역량이 있는지를 확인하기 👍
실습하기
1
SELECT
pd.ProductID AS "상품아이디",
pd.ProductName AS "상품명",
SUM(od.Quantity) AS "총수량"
FROM OrderDetails AS od
INNER JOIN Products AS pd
ON od.ProductID = pd.ProductID
GROUP BY pd.ProductID
HAVING SUM(od.Quantity) >= 200
ORDER BY SUM(od.Quantity) DESC;
2
SELECT
cs.CustomerID AS "고객아이디",
cs.CustomerName AS "고객이름",
SUM(Quantity) AS "주문량"
FROM Orders AS od
INNER JOIN Customers AS cs
ON cs.CustomerID = od.CustomerID
INNER JOIN OrderDetails AS od_detail
ON od.OrderID = od_detail.OrderID
GROUP BY cs.CustomerID
ORDER BY SUM(Quantity) DESC;
3
SELECT
cs.CustomerID AS "고객아이디",
cs.CustomerName AS "고객이름",
SUM(Quantity * Price) AS "지출금액($)"
FROM Orders AS od
INNER JOIN Customers AS cs
ON cs.CustomerID = od.CustomerID
INNER JOIN OrderDetails AS od_detail
ON od.OrderID = od_detail.OrderID
INNER JOIN Products AS pd
ON od_detail.ProductID = pd.ProductID
GROUP BY cs.CustomerID
ORDER BY SUM(Quantity * Price) DESC;
Last updated