题解 | #店铺901国庆期间的7日动销率和滞销率#

店铺901国庆期间的7日动销率和滞销率

http://www.nowcoder.com/practice/e7837f66e8fb4b45b694d24ea61f0dc9

参考了大佬的思路 注意外层查询的别名是可以在子查询中使用的

select distinct dt, round(cnt/total_cnt,3) sale_rate,round(1-cnt/total_cnt,3) unsale_rate
from
#统计10月1号到10月3号近7天的在销售产品数
(select 
date(event_time) dt,
(select count(distinct product_id) from
tb_product_info join 
tb_order_detail using(product_id)
join tb_order_overall
using(order_id)  
where timestampdiff(day,event_time,tol.event_time) between 0 and 6
and shop_id=901
) cnt,
#统计10月1号到10月3号近7天的已经上架的产品数
(select count(product_id) from tb_product_info 
where date(release_time)<= dt and shop_id=901
) total_cnt
from tb_order_overall tol
where date(event_time) between '2021-10-01' and '2021-10-03'
)
t1
order by dt
全部评论
该牛油正在参与牛客写题解薅羊毛的活动,牛币,周边,京东卡超多奖品放送,活动进入倒计时!快来捡漏啦https://www.nowcoder.com/discuss/888949?source_id=profile_create_nctrack&channel=-1
点赞 回复 分享
发布于 2022-04-27 12:15

相关推荐

双尔:反手回一个很抱歉,经过慎重考虑,您与我的预期暂不匹配,感谢您的投递
点赞 评论 收藏
分享
评论
2
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务