基本连接有问题
我有一个名为 tblSport 的表,其中包含 pkSportID 和 fldName 列。
我有一个名为 tblRespondentSport 的表,其中包含列 fkRespondentID 和 fkSportID。
我想返回运动 ID、运动名称和受访者人数。
这是我的查询:
SELECT s.pkSportID AS id, s.fldSport AS sport, r.COUNT(*) AS count FROM tblSport AS s LEFT JOIN tblRespondentSport AS r ON s.pkSportID = r.fkSportID
我收到 MySQL 1064 错误,它显示它位于 COUNT() 中的 * 附近。我是新加入的,所以我确信这是一件微不足道的事情。提前致谢。
I have a table called tblSport which contains the columns pkSportID and fldName.
I have a table called tblRespondentSport which contains the columns fkRespondentID and fkSportID.
I want to return the sport ID, the name of the sport, and the number of respondents.
Here's my query:
SELECT s.pkSportID AS id, s.fldSport AS sport, r.COUNT(*) AS count FROM tblSport AS s LEFT JOIN tblRespondentSport AS r ON s.pkSportID = r.fkSportID
I'm getting a MySQL 1064 error and it says its near the * in COUNT(). I'm new to joins so I'm sure its something trivial. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您缺少 Group BY
You are missing Group BY
我认为您需要将
r.COUNT(*) 更改为 COUNT(r.*).
甚至只是COUNT(*)
I think you need to change
r.COUNT(*) to COUNT(r.*).
or even justCOUNT(*)