select category_id,
sum(order_amount) as total_sales,
sum(case when customer_gender='男' then 1 else 0 end) as male_customers,
sum(case when customer_gender='女' then 1 else 0 end) as female_customers
from (
select *
from order_details
where order_date>='2024-01-01' and order_date<='2024-06-30'
) a join customer_info b on a.order_id=b.order_id
group by category_id
order by category_id

京公网安备 11010502036488号