Blair  - Soul Eater 1068. Product Sales Analysis I

• data analysis/SQL

1068. Product Sales Analysis I

oujin 2024. 2. 22. 22:15
728x90

테이블 생성코드

Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)
Create table If Not Exists Product (product_id int, product_name varchar(10))
Truncate table Sales
insert into Sales (sale_id, product_id, year, quantity, price) values ('1', '100', '2008', '10', '5000')
insert into Sales (sale_id, product_id, year, quantity, price) values ('2', '100', '2009', '12', '5000')
insert into Sales (sale_id, product_id, year, quantity, price) values ('7', '200', '2011', '15', '9000')
Truncate table Product
insert into Product (product_id, product_name) values ('100', 'Nokia')
insert into Product (product_id, product_name) values ('200', 'Apple')
insert into Product (product_id, product_name) values ('300', 'Samsung')

 

 

문제

 

 

 

 

해결코드

SELECT product_name,year, price
FROM Sales S
JOIN Product P ON S.product_id = P.product_id;

 

해설

Sales 테이블과 Product 테이블을 join 해주고

select  문에서 보고 싶은 컬럼인 product_name,year, price  만 출력하기

 

 

728x90

'• data analysis > SQL' 카테고리의 다른 글

1075. Project Employees I  (0) 2024.02.26
610. Triangle Judgement  (0) 2024.02.24
[leetcode] 1148. Article Views I  (0) 2024.02.20
[leetcode] 620. Not Boring Movies  (0) 2024.02.19
[leetcode] 175. Combine Two Tables  (0) 2024.02.16