susinlee 님의 블로그

Product Sales Analysis 1 본문

코드카타/SQL, Pandas

Product Sales Analysis 1

susinlee 2024. 12. 20. 08:57

[문제] https://leetcode.com/problems/product-sales-analysis-i/description/

Write a solution to report the product_name, year, and price for each sale_id in the Sales table.

Return the resulting table in any order.

The result format is in the following example.

 

[풀이]

Pandas

import pandas as pd

def sales_analysis(sales: pd.DataFrame, product: pd.DataFrame) -> pd.DataFrame:
    df = pd.merge(sales, product, on='product_id', how='inner')
    
    return df[['product_name', 'year', 'price']]

 

SQL

# Write your MySQL query statement below
SELECT p.product_name,
       s.year,
       s.price
FROM Sales s
LEFT JOIN Product p
    ON s.product_id = p.product_id

'코드카타 > SQL, Pandas' 카테고리의 다른 글

Rising Temperature  (0) 2024.12.21
Customer Who Visited but Did Not Make Any Transcations  (1) 2024.12.20
대충 만든 자판  (0) 2024.12.19
Replace Employee ID With The Unique Identifier  (0) 2024.12.19
Invalid Tweets  (0) 2024.12.19