«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Recent Posts
Today
Total
관리 메뉴

짜리몽땅 매거진

[SQL] 코멘토 프로젝트 - SQL 기본 문법 익히기 본문

Data/SQL

[SQL] 코멘토 프로젝트 - SQL 기본 문법 익히기

쿡국 2024. 5. 21. 15:24

출처 : w3schools

https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all

 

SQL Tryit Editor v1.6

WebSQL stores a Database locally, on the user's computer. Each user gets their own Database object. WebSQL is supported in Chrome, Safari, Opera, and Edge(79). If you use another browser you will still be able to use our Try SQL Editor, but a different ver

www.w3schools.com

 

문제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

 

문제 해설