SELECT
    o.category_id,
    SUM(o.order_amount) AS total_sales,
    SUM(CASE WHEN c.customer_gender='男' THEN 1 ELSE 0 END) AS male_customers,
    SUM(CASE WHEN c.customer_gender='女' THEN 1 ELSE 0 END) AS female_customers
FROM
    order_details AS o
    INNER JOIN
    customer_info AS c ON o.order_id=c.order_id
WHERE
    o.order_date BETWEEN '2024-01-01' AND '2024-06-30'
GROUP BY
    o.category_id
ORDER BY
    o.category_id;