with t1 as (select o.order_id,category_id,order_amount,order_date,customer_id,customer_gender,
case 
when customer_gender = '男' then 1
else 0 end as count_male,
case 
when customer_gender = '女' then 1
else 0 end as count_female
 from order_details as o 
join customer_info c 
on c.order_id = o.order_id
where date(order_date) between '2024-01-01'and '2024-06-30')
select category_id,sum(order_amount) as total_sales, sum(count_male) as male_customers, sum(count_female) as female_customers from t1
group by category_id