sql - 如何使用 MySQL 进行分组和计数

标签 sql mysql count group-by

我的数据如下所示:

ID  post_author post_title  guid
3309    21  Should somebody not yet on SQL 2008 wait for SQL 2008 R2, since it's near release?  http://sql.stackexchange.com/questions/379/should-somebody-not-yet-on-sql-2008-wait-for-sql-2008-r2-since-its-near-release
1695    429 How do we politely decline well meaning advice from the Grandmother?    http://moms4mom.stackexchange.com/questions/1208/how-do-we-politely-decline-well-meaning-advice-from-the-grandmother
556 173 Books on how to be a great dad  http://moms4mom.stackexchange.com/questions/1042/books-on-how-to-be-a-great-dad
160 30  Building an ice hockey net cam  http://photo.stackexchange.com/questions/8/building-an-ice-hockey-net-cam
159 30  Generic commercial photo release form   http://photo.stackexchange.com/questions/4/generic-commercial-photo-release-form

我需要创建一个查询,对 GUID 字段(根 URL)的一部分数据进行分组,并对每个字段的 POST_AUTHOR 进行计数。

我正在寻找的结果是这样的:

Site    Count of Authors
http://sql.stackexchange.com    1
http://moms4mom.stackexchange.com   2
http://photo.stackexchange.com  2

如果有人帮助我构建 SQL,我将不胜感激。

最佳答案

SELECT COUNT(POST_AUTHOR) AS AUTHOR_COUNT, GUID FROM TABLE_NAME GROUP BY GUID

关于sql - 如何使用 MySQL 进行分组和计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1589834/

相关文章:

excel - 计算特定文件夹中具有特定文件名的文件

sql - 在数据中查找指定模式--Hive

sql - Excel 聚合函数

PHP - 从多维数组插入数据库

python - pandas df 中当前唯一值的计数

php - 统计mysql中可用的数量

mysql - SQL 查询 - 打印同一行中一个表的最小值和最大值

sql - 如何使用通配符 (LIKE) 和数组 (IN) 进行选择?

mysql - 在 MySQL 中,如何从单个表加载多个表,同时保持引用完整性?

java - 如何在java中使用 vector 定义表模型