Q:

SQL query help needed joining and counting within a table

This is my second post related to my join. Now I want to have a table that has the sum of counts for the males and females... 
I have a table called babynames that looks abit like this:
firstname |sex |year |count 
Bob |M| 2010| 150
Bob |M| 2009| 100
Bob |M| 2008| 122
Bob |F| 2007| 2
Bob |F| 2001| 1

I've been able to count all the baby names that are both male and female with this query
SELECT 
  firstname, sum(count), sex
FROM babynames
GROUP BY firstname
HAVING COUNT(DISTINCT sex) = 2

resulting table: 
bob|375|M 

That is close to what I want....but
SELECT 
  firstname, sum(count), sex
FROM babynames GROUP BY firstname, sex

gives me the results: 
bob|372|M
bob|3|F

Now, i need to get the best of both worlds so that my table ONLY has names where the sex matches and ideally looks like this: 
firstname|male count| female count
bob |372|3

While I admit I need some practice with SQL, I'd appreciate some help pulling this query together. Thanks!!

A:

SELECT  firstname,
        SUM(CASE WHEN sex = 'm' THEN count END) MaleCount,
        SUM(CASE WHEN sex = 'f' THEN count END) FemaleCount
FROM    babynames 
GROUP   BY firstname

SQLFiddle Demo

