Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在尝试使用 SQL 中的 count 函数时遇到了一些麻烦。
我正在尝试计算具有特定名称的人数
例如:
Name | Number ============== Ivan | 9 Brody| 8 Ray | 7
并且如果有相同的实例按字母顺序排序。
任何帮助深表感谢!
使用COUNT()which is anAGGREGATE FUNCTION时需要有GROUP BY子句。尝试这个,
COUNT()
AGGREGATE FUNCTION
GROUP BY
SELECT Name, COUNT(name) FROM tableName GROUP BY Name ORDER BY COUNT(name) DESC
或者你可以添加ALIAS它
ALIAS
SELECT Name, COUNT(name) totalCount FROM tableName GROUP BY Name ORDER BY totalCount DESC