首页 > 其他 > 详细

LC 1384. Total Sales Amount by Year

时间:2020-05-01 12:14:08      阅读:67      评论:0      收藏:0      [点我收藏+]

link

技术分享图片

 

 

# Write your MySQL query statement below

select t3.product_id,p.product_name,year as report_year,amount as total_amount from 
(
select product_id,year,if(period_start>end or period_end<start,-1,(1+datediff(if(period_end>end,end,period_end),if(period_start<start,start,period_start)))*average_daily_sales) as amount
from
(
select * from Sales join 
(
select 2018 as year, 2018-01-01 as start, 2018-12-31 as end
union all
select 2019 as year, 2019-01-01 as start, 2019-12-31 as end
union all
select 2020 as year, 2020-01-01 as start, 2020-12-31 as end
)t1
)t2 
)t3 join Product p where t3.product_id=p.product_id and t3.amount>-1 
order by t3.product_id, report_year

 

LC 1384. Total Sales Amount by Year

原文:https://www.cnblogs.com/FEIIEF/p/12812818.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!