Products
+------------------+---------+
| Column Name | Type |
+------------------+---------+
| product_id | int |
| product_name | varchar |
| product_category | varchar |
+------------------+---------+
product_id는 이 테이블의 기본 키(고유 값을 갖는 열)입니다.
이 테이블에는 회사의 제품에 대한 데이터가 포함되어 있습니다.
Orders
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| product_id | int |
| order_date | date |
| unit | int |
+---------------+---------+
이 테이블에는 중복 행이 있을 수 있습니다.
product_id는 Products 테이블의 외래 키(참조 열)입니다.
unit은 order_date에서 주문한 제품 수입니다.
2020년 2월에 100개 이상 주문된 제품의 이름과 그 수량을 구하는 솔루션을 작성합니다.
결과 테이블을 임의의 순서로 반환합니다.
select A.product_name , sum(B.unit) as unit from Products A join Orders B on A.product_id = B.product_id where 1=1 and date_format(order_date, '%Y%m') = '202002' group by A.product_name having sum(B.unit) >= 100 ;