题解 | #某宝店铺动销率与售罄率#

某宝店铺动销率与售罄率

https://www.nowcoder.com/practice/715dd44c994f45cb871afa98f1b77538

# 3/21 11:06 ~ 
# 字段:style_id、pin_rate、sell-through_rate
# pin_rate动销率 = 有销售的SKU数量 / 在售SKU数量 
# 其中在售sku数量 = 库存 - 已经出售的sku数量, 需要注意的一点是sku数量,不是sku种类噢!~
# sell-through_rate售罄率 = GMV / 备货值# 备货值 = 吊牌价*库存数

# tb1:计算在售sku数量(库存量-出售的sku数量) 【先求出售的sku数量,再左连接库存量】
with tb1 as(
    select style_id, sum(sales_num) as sum_sales_num
    from sales_tb left join product_tb using(item_id)
    group by style_id
),

# tb2: 求总库存
tb2 as(
    select style_id,sum(inventory) as sum_inventory
    from product_tb 
    group by style_id
),

# tb3:链接库存 求动销率【动销率 = 出售的SKU数量 / 目前在售的SKU数量】
tb3 as(
    select style_id , 
    round(round(sum_sales_num/(sum_inventory-sum_sales_num),4)*100,2) as pin_rate
    from tb1 left join tb2 using(style_id)
),

# tb4:求取备货值
tb4 as(
    select style_id,sum(tag_price*inventory) as bhz
    from product_tb 
    group by style_id 
),


# tb5:求	sell-through_rate 售罄率(GMV / (吊牌价*库存数))
# 此处的库存数暂定用 原始库存数量 进行计算
tb5 as(
    select style_id,
    sum(sales_price) as GMV
    from sales_tb left join product_tb using (item_id)
    group by style_id 
)

# 结果表
select style_id, pin_rate, round(round(GMV/bhz,4)*100,2) as sell_through_rate
from tb3 left join tb4 using(style_id) left join tb5 using(style_id)
order by style_id






全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务