我有这个查询:
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
我不知道如何做到这一点可以帮助我吗?
答案 0 :(得分: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