-1

In my Table of TEAMS with relational table>rows for its PLAYERS

Each Team has 3 or more players Each Player associated with the team has a points column

I need to retrieve only the TEAM w/c has accumulated player points of 300 or greater

I have gone to this point so far:

enter image description here

Problem with this is it returns a result set contain ALL the rows in the TEAMs table.

enter image description here

How do I make it return result only if SUM is > than , say, 300?

I tried adding:

**WHERE total_points >= '300'**

but obviously that returns an "unknown column" error.

Any ideas?

PS I could easily get what i want via PHP > loop but it's such a waste on Server resource to be loading THOUSANDS of Team rows just to get a few that meets a criteria..

BrownChiLD
  • 3,545
  • 9
  • 43
  • 61

2 Answers2

1

try using HAVING clause instead of WHERE

HAVING total_points >= 300
Chatz
  • 338
  • 2
  • 10
1

Use the having clause .. it applies to groupings. (Similar to where)

so after the group put having sum(players.points)>300

Dumitrescu Bogdan
  • 7,127
  • 2
  • 23
  • 31