2012-11-27 86 views
2

我有這個疑問:MySQL的過濾器

SELECT a.*, a.id AS id_player, (SELECT COUNT(id) FROM `vd7qw_footsal_goals` WHERE a.id = id_player AND g.id = id_group) AS goals, 
team.* FROM `vd7qw_footsal_players` AS a 

LEFT JOIN vd7qw_footsal_teams AS team ON team.id= a.id_team 

LEFT JOIN vd7qw_footsal_teamofgroup AS tog ON tog.id_team = team.id 4 

LEFT JOIN vd7qw_footsal_groups AS g ON g.id = tog.id_group 
WHERE g.id IN (SELECT id_group from `vd7qw_footsal_groupofleague` WHERE id_league = 2) 
AND (a.state IN (1)) AND goals > 0 ORDER BY goals DESC 

,我希望通過有目標

上面的查詢玩家過濾其resaults這部分goals > 0我不有錯誤不知道該怎麼做才能幫助我?

+1

什麼錯誤? –

+0

列'目標'不存在 – Viszman

回答

3

試試這個:

SELECT * FROM 
(SELECT a.*, a.id AS id_player, (SELECT COUNT(id) FROM `vd7qw_footsal_goals` WHERE a.id = id_player AND g.id = id_group) AS goals, 
team.* FROM `vd7qw_footsal_players` AS a 

LEFT JOIN vd7qw_footsal_teams AS team ON team.id= a.id_team 

LEFT JOIN vd7qw_footsal_teamofgroup AS tog ON tog.id_team = team.id 4 

LEFT JOIN vd7qw_footsal_groups AS g ON g.id = tog.id_group 
WHERE g.id IN (SELECT id_group FROM `vd7qw_footsal_groupofleague` WHERE id_league = 2) 
AND (a.state IN (1))) AS A WHERE goals > 0 ORDER BY goals DESC