题解 | 店铺901国庆期间的7日动销率和滞销率
店铺901国庆期间的7日动销率和滞销率
https://www.nowcoder.com/practice/e7837f66e8fb4b45b694d24ea61f0dc9
select dt,round(num1/num2,3) sale_rate,round((num2-num1)/num2,3) unsale_rate from( select distinct date(event_time) dt, (select count(distinct tod.product_id) from tb_order_detail tod join tb_order_overall too on tod.order_id = too.order_id join tb_product_info tpi on tpi.product_id = tod.product_id where shop_id = '901' and timestampdiff(day,event_time,t2.event_time) between 0 and 6) num1, //我就想不明白为啥这里日期比较必须引用t2.date而不能用dt别名呢???????? (select count(product_id) from tb_product_info where shop_id = '901' ) num2 from tb_order_overall t2 where date(event_time) between '2021-10-01' and '2021-10-03') as t1
来人救救我-----------------------------------------