mySQL Error with WHERE clause and group by clause : [enter image description here][1]


I'm trying to write a query that retrieves the names of all salespeople that have more than $1300 in orders from the tables above. (each salesperson only has one ID.)

  [1]: https://i.stack.imgur.com/KUbgq.png

Here is my attempt:

SELECT name, sum(amount)

FROM salesperson

JOIN orders

ON salesperson.ID = orders.salesperson_id

WHERE sum(amount) > 1300 

GROUP BY name; 



However, it displays the error: ERROR 1111 (HY000): Invalid use of group function.

When I remove where clause, it works fine and returns following:


[enter image description here][2]


  [2]: https://i.stack.imgur.com/EwJgy.png

Which is pretty similar to what I want except that there's no filter for sum(amount) less than 1300.

What did I do wrong with where clause and how can I solve it? I need urgent help.

Thank you.