mysql - Wrong SQL query (beginner)
问题描述
I am new in SQL, and I am learning alone on Udemy. I came across multiple questions, and I am struggling with one of them:
What is wrong with this SQL query?
SELECT sport, count(*)
FROM activities
WHERE username IN ‘tony’
GROUP BY 1;
I have two hypothesis: 1 - If the field 'sport' in activities is filled with string values, then we can't use count. 2 - the last statement should be rather:
WHERE username in:‘tony’ GROUP BY 1;
I would be happy to have your feedback on the question and learn from you! Thanks
解决方案
搜索 IN 将使用 with () 圆括号
SELECT sport, count(*)
FROM activities
WHERE username IN ('tony')
GROUP BY 1;
推荐阅读
- selenium - 如何在 Cloud Builders 中成功运行 Protractor e2e 测试?
- javascript - 如何解析html页面并通过符号
- html - 我该如何解决这个问题?
- arduino - 如何增加一个环绕整数?(0-360角度传感器环绕)
- django - Django 错误:必须使用切片将精确查找的 QuerySet 值限制为一个结果
- ruby - Ruby中的每个循环都从子节点开始
- asp.net-web-api - 从邮递员调用时,作为 json 发送的对象数据未在对象模型中序列化
- touch - 如何从 gtk 手势滑动信号确定滑动方向
- java - 如何根据条件在recyclerview中隐藏json对象?
- c# - JsonWriter 和 JsonTextWriter 有什么区别?