Image Alt photo_exhibition

Write a solution to report the products that were only sold in the first quarter of 2019. That is, between 2019-01-01 and 2019-03-31 inclusive.

Return the result table in any order.

The result format is in the following example.

Image Alt photo_exhibition

단계별로 생각하고 쿼리를 짜자.

  1. Product 테이블의 product_nameSales 테이블에 붙인다.
  2. Sales 테이블의 product_id를 GROUP BY로 묶는다.
  3. Sales 테이블의 sale_date가 ‘2019-01-01’ 와 ‘2019-03-31’ 사이에만 있어야 하므로, MIN(Sales.sale_date) >= "2019-01-01" AND MAX(Sales.sale_date) <= "2019-03-31"
SELECT p.product_id
      ,p.product_name
FROM Sales s
INNER JOIN Product p ON s.product_id = p.product_id 
GROUP BY s.product_id
HAVING MIN(s.sale_date) >= "2019-01-01" AND MAX(s.sale_date) <= "2019-03-31";