SQL查询,我做错了什么?我是MySQL的新手
SELECT agency_name, Count(*) AS complaint_type_count
FROM service_request_xs
GROUP BY agency_name
ORDER BY Count(*) DESC;
- 解决方案上传
SELECT agency_name, Count(*) AS complaint_type_count
FROM service_request_xs
GROUP BY agency_name
ORDER BY Count(*) DESC;
- solution uploaded
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须告诉 count() 函数要计算什么。您可以插入单个列,或者插入 * 等所有列。但是您必须计算一些内容。
这是一个小提琴,展示了它是如何工作的:
https://www.db-fiddle.com/f/dbPnE4BXv8oRRkQY4WQs8v/1
You have to tell the count() function what to count. You can insert an individual column, or * for all of it etc. But you have to count something.
This is a fiddle, showing how it works:
https://www.db-fiddle.com/f/dbPnE4BXv8oRRkQY4WQs8v/1
通常,当您使用
Count()
函数时,您必须在括号之间添加列名;例如:Count(complaint_type)
,否则 SQL 将不知道要计数什么。您必须在
SELECT
和ORDER BY
中执行此操作。您还可以使用
Count(*)
来计算表中的所有行。Usually, when you use the
Count()
function, you have to add a column name between the parentheses; such as:Count(complaint_type)
or else SQL will not know what to count.You have to do this in the
SELECT
and theORDER BY
.You can also use
Count(*)
to count all lines in your table.