Mysql根据计数选择PageId

时间:2021-07-22 22:47:16

I am trying to select a page id based on how many comments there are, this is what I have so far:

我试图根据有多少评论选择页面ID,这是我到目前为止:

SELECT PageId FROM test.comments  Order By COUNT(Id);

How can I just select the pageId's and order them by the amount of rows that contain that page id? Thanks,

如何选择pageId并按包含该页面ID的行数对它们进行排序?谢谢,

1 个解决方案

#1


0  

In order to accomplish what you are looking for you need to utilize group by.

为了实现您所寻找的目标,您需要利用分组。

The GROUP BY statement is used in with aggregate functions to group the result set by one or more columns.

GROUP BY语句与聚合函数一起使用,以按一列或多列对结果集进行分组。

The following query groups every identical page id (ie. based on how many rows contain that page id) and gives you a count of how many times each id repeats:

以下查询对每个相同的页面ID进行分组(即基于包含该页面ID的行数),并计算每个id重复的次数:

SELECT PageId, COUNT(*) FROM test.comments GROUP BY PageID ORDER BY COUNT(*)

#1


0  

In order to accomplish what you are looking for you need to utilize group by.

为了实现您所寻找的目标,您需要利用分组。

The GROUP BY statement is used in with aggregate functions to group the result set by one or more columns.

GROUP BY语句与聚合函数一起使用,以按一列或多列对结果集进行分组。

The following query groups every identical page id (ie. based on how many rows contain that page id) and gives you a count of how many times each id repeats:

以下查询对每个相同的页面ID进行分组(即基于包含该页面ID的行数),并计算每个id重复的次数:

SELECT PageId, COUNT(*) FROM test.comments GROUP BY PageID ORDER BY COUNT(*)