Jump to content

Simple count query help?


Mr Chris

Recommended Posts

Hi Guys,

 

I have a table join that works fine which lists goalscorers in a football season:

 

SELECT th.team_id, 
       th.team_name AS team, 
       th.league, 
       re.report_id, 
       re.competition,
       s.player_id AS player, 
       s.report_id, 
       players.player_name, 
       players.position, SUM( s.goals ) AS total_goals
FROM player_stats s
INNER JOIN teams th ON 
  th.team_id = players.team_id
INNER JOIN 
  reports re ON re.report_id = s.report_id
LEFT OUTER JOIN players ON players.player_id = s.player_id
WHERE re.competition = '$x'
GROUP BY players.player_id
ORDER BY total_goals DESC

 

However on the count query;

 

players.position, SUM( s.goals ) AS total_goals

 

it also outputs all players in the database even if they have scored no/zero goals. Which I don't want.  I only want a list of players who have scored goals  So I want to add in the line something like:

 

WHERE total_goals !=''

 

Somewhere in my code to achieve this - Can anyone help?

 

Thanks

 

Chris

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.