Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Posts
    1

    Unanswered: counting each male and female sum for each country

    Hi, I have a table like this:

    'statistic' table:

    country | gender|
    ------------------
    usa | male |
    uk | female |
    usa | male |
    usa |female |
    china | male |
    china | female |



    how can i make a query that have output like this:

    country | male | female |
    --------------------------
    usa | 2 | 1 |
    uk | 0 | 1 |
    china | 1 | 1 |


    thanks in advance !

    sanders

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    Code:
    select country,
    sum(case when gender = 'm' then 1 else 0 end) as male,
    sum(case when gender = 'f' then 1 else 0 end) as female,
    from yourtable
    group by country
    should do what you want.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •