1.Country 별로 ContactName이 ‘A’로 시작하는 Customer의 숫자를 세는 쿼리를 작성하세요.
SELECT country, count(1)
FROM customers
where ContactName like 'A%'
group by country
2. Customer 별로 Order한 Product의 총 Quantity를 세는 쿼리를 작성하세요.
SELECT c.CustomerID, sum(quantity)
FROM Customers as c, orders as o, orderdetails as ot
where c.CustomerID = o.CustomerID
and o.OrderID = ot.OrderID
group by c.CustomerID
3. 년월별, Employee별로 Product를 몇 개씩 판매했는지와 그 Employee의 FirstName을 표시하는 쿼리를 작성하세요.
SELECT EmployeeID, DATE_FORMAT(OrderDate,'%Y-%m-&d')
FROM [Orders]
GROUP BY DATE_FORMAT(OrderDate,'%Y-%m-&d')
select substr(o.OrderDate,1,7), o.EmployeeID, E.FirstName, o.OrderID
from orders o
left join OrderDetails OD ON o.OrderID =OD.OrderID
left join Employees E ON o.EmployeeID=E.EmployeeID
group by substr(o.OrderDate,1,7),o.EmployeeID, E.FirstName