[LeetCode] SQL 50 / ORACLE / 1068. Product Sales Analysis 1

2024. 1. 6. 16:33Coding/LeetCode-SQL

문제 링크

https://leetcode.com/problems/product-sales-analysis-i/?envType=study-plan-v2&envId=top-sql-50

 

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

 

문제

 

코드

/* Write your PL/SQL query statement below */
SELECT B.product_name, A.year, A.price
FROM Sales A, Product B
WHERE A.product_id = B.product_id;

 

1. Oracle의 INNER JOIN 방법을 알면 풀리는 문제. null 값에 대한 언급이 없으므로 INNER JOIN을 해주고, 이때 기준이 되는 칼럼은 두 칼럼의 기본키인 product_id로 해주면 된다.