짜리몽땅 매거진
[SQL] 코멘토 프로젝트 - SQL 기본 문법 익히기 본문
출처 : w3schools
https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all
문제1. Country 별로 ContactName이 ‘A’로 시작하는 Customer의 숫자를 세는 쿼리를 작성하세요.
정답 쿼리
select Country, count(CustomerID) as cnt
from Customers
where ContactName like 'A%'
group by Country
문제 해설
문제2. Customer 별로 Order한 Product의 총 Quantity를 세는 쿼리를 작성하세요.
정답 쿼리
select a.CustomerID, sum(b.Quantity) as TotalQuantity
from Orders a
join OrderDetails b
on a.OrderID = b.OrderID
group by a.CustomerID
문제 해설
문제3. 년월별, Employee별로 Product를 몇 개씩 판매했는지를 표시하는 쿼리를 작성하세요.
정답 쿼리
select a.OrderDate, a.EmployeeID, sum(b.ProductID) as TotalProduct
from Orders a
join OrderDetails b
on a.OrderID = b.OrderID
group by OrderDate, EmployeeID
문제 해설
'Data > SQL' 카테고리의 다른 글
[SQL] 코멘토 프로젝트 - SQL을 활용해 다양한 지표 추출하기 (0) | 2024.05.28 |
---|---|
[SQL] solvesql 코딩테스트 연습9 (0) | 2024.05.27 |
[SQL] solvesql 코딩테스트 연습8 (0) | 2024.05.08 |
[SQL] solvesql 코딩테스트 연습7 (0) | 2024.04.29 |
[SQL] solvesql 코딩테스트 연습6 (0) | 2024.04.22 |