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??

Hi you must use HAVING to condition an aggregate.

see this:

``````HAVING SUM(GOAL) >= 10
``````

thanks,
Mokong

Ohhh, thank you, it works :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.