코린이의 소소한 공부노트

[LeetCode/Easy] 1327. List the Products Ordered in a Period 본문

코딩테스트 풀이/SQL

[LeetCode/Easy] 1327. List the Products Ordered in a Period

무지맘 2023. 6. 11. 22:15

1. Input

1) Table: Products (pk: product_id)

2) Table: Orders (no pk)

 

2. Output

1) 상품들 중 20202월에 최소 100개 이상 팔린 제품의 이름과 그 양을 출력

- 출력 순서는 상관 없다.

 

3. Example

 

4. Code

1) 첫 코드(2023/06/11)

select p.product_name, o.unit
from Products p, (
    select product_id, sum(unit) as unit
    from Orders
    where order_date between '2020-02-01' and '2020-02-29'
    group by product_id
) o
where p.product_id = o.product_id and unit>=100;

- 21%