Hi there,
Does anyone know if i could 2 columns 1 by ascending and the other one by descending. I have 2 tables, both related by sport code:
Code:
Table: sports_played
parent_id child_id sport_code level
1 1 SW Advanced
1 1 SR Advanced
2 1 TN Intermediate
2 2 TN Beginner
2 2 HK Advanced
3 1 SR Intermediate
3 1 RG Intermediate
3 1 BS Beginner
5 1 BS Advanced
Table: sport
sport_code sport_name winter summer_sport coach_id
SW Swimming Yes Yes 4
TN Tennis Yes Yes
RG Rugby Yes No 1
BS Basketball No Yes 2
HK Hockey No Yes 2
SR Soccer Yes No 2
SL Sailing No Yes 4
And what I need to have is a table that lists how many children play each summer sport at each of the levels (Beginner, Intermediate, and Advanced).
And the ordering has to be done listed in descending order of the
sport_name , then in ascending order of number of children who play the sport at the level.
My SQL statements are:
Code:
SELECT sport.sport_name, Count(sports_played.level) As SumOfLevels
FROM sports_played RIGHT OUTER JOIN sport
ON sports_played.sport_code =
sport.sport_code
AND sport.summer_sport = ‘Yes’
ORDER BY sport.sport_name DESC;
SELECT sport.sport_name, Count(sports_played.level) AS SumOfLevels
FROM sports_played LEFT OUTER JOIN sport
ON sports_played.sport_code = sport.sport_code
AND sport.summer_sport = ‘Yes’
ORDER BY sports_played.level ASC;
The reason I have 2 tables is (i thought) i can't have both sport_name Desc and sports_played ASC order. since the order will both collide with each other, and will give me an error.
Another question is can I use Count() to differentiate each 3 level, even though they are strings? Is it possible?
regards,
hulan