首页 > 解决方案 > 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

标签: mysqlsql

解决方案


搜索 IN 将使用 with () 圆括号

SELECT sport, count(*) 
FROM activities 
WHERE username IN ('tony')
GROUP BY 1;

推荐阅读