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.
所以基本上,我有一个不同名称的列表,可以说
John Mary Pedro
John
Mary
Pedro
我有一个返回的查询John John Mary Pedro Mary John Pedro Mary Mary
John John Mary Pedro Mary John Pedro Mary Mary
我想要一个同时接受这两个并返回的查询
John 3
3
Mary 4
4
Pedro 2
2
但我完全不知道如何做到这一点。
提前致谢
这应该很简单。
您需要使用聚合函数COUNT()来计算每个名称的实例数。
COUNT()
SELECT Name, COUNT(*) AS totalCount FROM tableName GROUP BY Name
这是另一种编写 SQL 查询的方法:
SELECT Name, count(*) OVER (PARTITION BY Name) as "occurrence" from yourTable;
这里分析函数用于查找表中名称的计数。