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.
我试图想出一个表格来显示表格中常见元素的总数。
例如。我有一个包含值的表 A:
colName ============= a b b c c c d
有什么方法可以得出结果显示:
colName totalCount ================== a 1 b 2 c 3 d 1
这是一个使用聚合函数COUNT和GROUP BY子句的简单查询。
COUNT
GROUP BY
SELECT colName, COUNT(colName) totalCount FROM tableName GROUP BY colName
totalCount被称为ALIASCOUNT(colName)
totalCount
COUNT(colName)