SELECT productline, count(productline)
FROM products
GROUP BY productline;
SELECT productcode, SUM(quantityordered)
FROM orderdetails
WHERE orderlinenumber =1
GROUP BY productcode;
SELECT productline, MAX(msrp)
FROM products
GROUP BY productline
❔ 문제 1: orders 테이블에서 각 상태(status)별로 주문 개수를 구하라.
SELECT status, COUNT(orderNumber) AS OrderCount
FROM orders
GROUP BY status;
❔ 문제 2: orderdetails 테이블에서 각 제품 코드(productCode)별로 주문된 총 수량(quantityOrdered)를 구하라.
SELECT productCode, SUM(quantityOrdered) AS TotalOrdered
FROM orderdetails
GROUP BY productCode ;
❔ 문제 3: products 테이블에서 제품 라인(productline)별 제품 개수를 조회하라.
SELECT productLine, COUNT(productCode) AS ProductCount
FROM products
GROUP BY productLine;
❔ 문제 4: product 테이블에서 각 제품 라인(productline)별로 제품의 최대 가격(buyPrice)과 최소 가격(buyPrice)를 계산하라.
SELECT productLine, MAX(buyPrice) AS maxPrice, MIN(buyPrice) AS minPrice
FROM product
GROUP BY productLine;
❔ 문제 5: customers 테이블에서 각 고객 도시(city)별로 평균 크레딧 한도(creditlimit) 상위 5개를 조회하라.
SELECT city, AVG(creditLimit) AS avgCreditLimit
FROM customers
GROUP BY city
ORDER BY avgCreditLimit DESC
LIMIT 5;
❔ 문제 6: orderdetails 테이블에서 주문 번호(orderNumber)별로 총 주문 총액(priceEach * quantityOrdered) 상위 5개를 계산하라.
SELECT orderNumber, SUM(priceEach*quantityOrdered) AS totalOrderPrice
FROM orderdetails
GROUP BY orderNumber
ORDER BY totalOrderPrice DESC
LIMIT 5;
❔ 문제 7: customers 테이블에서 각 국가(country)별로 고객 수가 많은 상위 5개를 조회하라.
SELECT country, COUNT(customerNumber) AS customerNumber
FROM customers
GROUP BY country
ORDER BY customerNumber DESC
LIMIT 5;
❔ 문제 8: products 테이블에서 productScale이 '1:10'인 제품 라인(productline)별로 제품의 평균 가격(buyPrice)를 구하라.
SELECT productLine, AVG(buyPrice) AS avgPrice
FROM products
WHERE productScale = '1:10'
GROUP BY productLine
;