Skip to content
Advertisement

select sum where condition is true and count > 3

I have two tables.

  • FootballPlayers with columns Id_footballplayer, Last_Name, Fisrt_Name, Age
  • Transfers with columns Id_transfer, Name_club, price, date, acceptance (yes or no), code_footballplayer

How can I write a SQL query to select the last names of the players and the sum of the successful transfers carried out by them, the number of which exceeds 3?

I already wrote a query that displays the total amount of all successful transfers for each player

But I don’t know how to add a condition if the number of successful transfers is more than 3

Advertisement

Answer

Since this is a group scenario, after theGROUP BY you probably want:

The HAVING clause works very similarly to WHERE, but is applied differently.


An alternative would be the sub-query:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement