题解 | 电商平台想要了解不同商品在不同月份的销售趋势

电商平台想要了解不同商品在不同月份的销售趋势

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

select
    product_id,
    product_name,
    sum(sales_amount) as total_sales,
    max(sales_amount) as max_monthly_sales,
    min(sales_amount) as min_monthly_sales,
    round(avg (sales_amount),0) as avg_monthly_sales
from
    (
        select
            s.product_id as product_id,
            product_name,
            sale_month,
            sum(quantity) as sales_amount
        from
            sales_underline as s
            inner join products_underline as p on s.product_id = p.product_id
        where
            sale_month between '2024-01' and '2024-06'
        group by
            s.product_id,
            sale_month
    ) as summary_sales
group by
    product_id,
    product_name
order by
    product_id;

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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