Link to home
Start Free TrialLog in
Avatar of Elizabeth G
Elizabeth GFlag for United States of America

asked on

SQL Query for pivot and calculation.

Am trying to write a sql query to get the data in a particular format. Please see my actual data below and the result am trying to get.

Sport            Team                No of Females                No of males

Baseball                    Varsity                             20                                                 0
Baseball                     Varsity                                                                                 20
Football                    Varsity                                                                                   15

Above is the format of the table and data in the actual database.
Now i want to get the data in this below format.

                                  Female Only                 Male only                   Total
Sports                           1                                    2                                  2
Teams                           1                                    2                                 3
Participants                20                                 35                                 55

Please help me with the sql query , I tried using pivot and count of the columns but i couldn't achieve the way i wanted. Thanks for your help!.
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Elizabeth G

ASKER

Thank you so much !. I got it to work with the help of your Query.
You're welcome!  (Btw, this q of yours put me over 10M point mark, Thanks!)