본문 바로가기

Algorithm/Implementation

(SQL) - LeetCode (easy) 1068. Product Sales Analysis I

반응형

https://leetcode.com/problems/product-sales-analysis-i/

 

Product Sales Analysis I - LeetCode

Can you solve this real interview question? Product Sales Analysis I - Table: Sales +-------------+-------+ | Column Name | Type | +-------------+-------+ | sale_id | int | | product_id | int | | year | int | | quantity | int | | price | int | +-----------

leetcode.com

join을 사용해보는 문제였습니다.

📕 풀이방법

📔 풀이과정

1. product_id를 fk로 공유하고 있으므로 left outer join을 사용해도 무방합니다. (다른 종류의 join을 사용해도 됩니다.)

2. ansi sql문을 사용해 db에 상관없이 실행 가능하도록 작성해줍니다.


📕 Code

📔 ANSI SQL

select product_name, year, price from sales s
left outer join product p on s.product_id = p.product_id

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.