题解 | 查询出每个品牌在不同月份的总销售额以及购买该品牌商品的用户的平均年龄

查询出每个品牌在不同月份的总销售额以及购买该品牌商品的用户的平均年龄

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

with od as(
select o.order_id,category_id ,order_amount,order_date,customer_gender
from order_details o
left join customer_info c
on o.order_id = c.order_id
where order_date between '2024-01-01' and  '2024-06-30'
)

select od.category_id
, sum(order_amount) total_sales
, sum(if(customer_gender='男',1,0)) male_customers
, sum(if(customer_gender='女',1,0)) female_customers
from od
group by 1

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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