题解 | 对商品的销售情况进行深度分析

对商品的销售情况进行深度分析

https://www.nowcoder.com/practice/d6ced1b60af64a4998169ae717672e8e

with t1 as
(
select
    category product_category,
    age_group,
    round(sum(quantity*price),2) total_sales_amount
from
    products p
    join sales s on p.product_id = s.product_id
    join customer_info c on s.sale_id = c.sale_id
group by 
    category,
    age_group
),t2 as
(
select
    category product_category,
    round(sum(quantity*price),2) total_sales_amount
from
    products p
    join sales s on p.product_id = s.product_id
    join customer_info c on s.sale_id = c.sale_id
group by 
    category
)
select
    t1.product_category,
    age_group,
    t1.total_sales_amount,
    round(t1.total_sales_amount/t2.total_sales_amount,2) purchase_percentage
from
    t1 join t2 on t1.product_category = t2.product_category
order by
    t1.product_category,
    purchase_percentage desc

全部评论

相关推荐

07-15 11:43
门头沟学院 Java
点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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