计算比赛的参与者

时间:2017-07-06 17:19:57

标签: sql postgresql

我有这样的架构http://sqlfiddle.com/#!17/30859/1,正如你可以看到的那样SQL小提琴我有查询需要改进,实际上我需要添加新列,它会给我每个锦标赛的参与者总数,我不知道我怎么能这样做,我尝试了亚选但没有任何成功。在此先感谢您的帮助

1 个答案:

答案 0 :(得分:1)

SELECT t.id, t.name as tournamentName, m.name as creator, s.name as 
sponsorName,
(count * from member_tournament mt where mt.tournament_id=t.id) members
FROM tournament t 
LEFT JOIN member m ON m.id = t.member_id 
LEFT JOIN sponsor s ON s.id = t.sponsor_id