MySQL5.1用连接和计数查询

时间:2012-12-02 20:16:13

标签: mysql join count

我有以下查询:

select teams.`team_name`, count(matches.`played_team`) 
from teams 
join matches on teams.`team_number` = matches.`played_team` 
group by teams.`team_name`

用于显示球队名称,球队编号以及他们所参加的比赛数量。 我希望在此查询中添加一个WHERE子句,该子句仅计算2011-01-01之后播放的游戏数。 matches.date保存有关比赛日期的信息。 谢谢!

1 个答案:

答案 0 :(得分:0)

select teams.`team_name`, count(matches.`played_team`) 
from teams 
join matches on teams.`team_number` = matches.`played_team`
WHERE `matches.date` > '2011-01-01' 
group by teams.`team_name`