题解 | 查询出每个品牌在不同月份的总销售额以及购买该品牌商品的用户的平均年龄
查询出每个品牌在不同月份的总销售额以及购买该品牌商品的用户的平均年龄
https://www.nowcoder.com/practice/a50c67d3374f4d0e85869d3e48e02c0a
select
category_id,
sum(order_amount) as total_sales,
sum(if(customer_gender = '男', 1, 0)) as male_customers,
sum(if(customer_gender = '女', 1, 0)) as female_customers
from
order_details
left join customer_info using (order_id)
where
order_date between '2024-01-01' and '2024-06-30'
group by
category_id
order by category_id
