Snoopy [리트코드/SQL] 33. Sales Analysis III (1084)
코딩테스트/리트코드 SQL

[리트코드/SQL] 33. Sales Analysis III (1084)

Sooyoon Jeong 2023. 2. 14.

🤔 문제 분석

1) Write an SQL query that reports the products that were only sold in the first quarter of 2019.

That is, between 2019-01-01 and 2019-03-31 inclusive.

 

💡 풀이

SELECT DISTINCT S.product_id, P.product_name
FROM Sales AS S
    INNER JOIN Product AS P ON S.product_id = P.product_id
WHERE S.product_id NOT IN (SELECT Sales.product_id
                           FROM Sales
                           INNER JOIN Product ON Sales.product_id = Product.product_id
                           WHERE sale_date NOT BETWEEN "2019-01-01" AND "2019-03-31")

댓글