0

Using SQL I have to SUM the total of each game but I can only select the games that have more than 10 scores in total .
So select GameNo,sum(goals) from tblGame, tblAthlete.

But I'm stuck on the 'where' bit.....select GameNO where (sum(goals)>=10);
So not only do I have to calculate the goals for each games, But I can only select the games that have more than 10 scores
Any suggestions for this query?
Below, I have given a little example.

I want to only list the games that have more than 10 scores,if you look below the answer is **Game2 & Game3 **
so in game1 the total of scoring was 5
game2 the total of scoring was 10
game3 the total of scoring was 12

Games1
Athletes scoring
Athlete 1 = 4 goals
Athlete 2 = 0 goals
Athlete 3 = 0 goals
Athlete 4 = 1 goals

Games2
Atheletes scoring
Athlete 1 = 4 goals
Athlete 2 = 5 goals
Athlete 3 = 0 goals
Athlete 4 = 1 goals

Games3
Athletes scoring
Athlete 1 = 2 goals
Athlete 2 = 4 goals
Athlete 3 = 2 goals
Athlete 4 = 4 goals

So, How would I SUM the total and only select games that only have more than 10 scores in total??
Please help me out here!!! thanks

2
Contributors
2
Replies
13
Views
4 Years
Discussion Span
Last Post by abzy1991
1

Hi you must use HAVING to condition an aggregate.

see this:

HAVING SUM(GOAL) >= 10

thanks,
Mokong

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.