QuXiangjie / Study-Review

自己欠缺的还太多了,希望通过总结每天的学习内容,整理每天的思绪来丰富自己的知识库。我想成为一名优秀的金融数据分析师,并行发展技术与商业业务。博客内容为:数理统计、财务业务、Python(数据分析及可视化)、Excel(数据分析)、SQL、英文
0 stars 0 forks source link

1070. Product Sales Analysis III #26

Open QuXiangjie opened 4 months ago

QuXiangjie commented 4 months ago

1070. Product Sales Analysis III

/*
with cte as
(
    select  product_id, year as first_year, quantity, price, 
            dense_rank() over(partition by product_id order by year) as denserank
    from Sales
)
select product_id, first_year, quantity, price
from cte 
where denserank=1
*/

Select  product_id, year as first_year, quantity, price
From Sales
Where (product_id, year) in (Select  product_id, MIN(year) From Sales Group by product_id)

The first solution can change the number of the year, the second solution is easier.