2

我有这个查询:

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

我想通过有目标的玩家过滤它的结果

上面的查询在这部分有错误goals > 0我不知道该怎么做任何1可以帮助我吗?

4

1 回答 1

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
于 2012-11-27T13:17:44.337 回答