简体   繁体   English

mysql php COUNT由GROUP BY列中的相同值回显

[英]mysql php COUNT by same value in column GROUP BY to echo out

I'm trying to figure out a solution to a query. 我正在尝试找出查询的解决方案。

Question : 题 :

I need to find the sum of rows which have the same value in a certain column. 我需要找到某一列中具有相同值的行总和 From this I then need to echo out certain bits of information along with the total count each value is seen (ie if 'project_id' has two rows with the same value as 11122 then the total count will be 2). 然后,我需要从中回显出某些信息位以及总计数,可以看到每个值(即,如果“ project_id”有两行的值与11122相同,则总计数将为2)。 I don't know the values I will need as these will be random project numbers in my table. 我不知道所需的值,因为这些值是表中的随机项目编号。

The column name I need to count by is 'project_id'. 我需要计算的列名称是“ project_id”。

I can't figure out how to echo in the following way: 我不知道如何通过以下方式回显:

Project ID = 11122 Total Reviews = 2 项目ID = 11122总评论= 2

Project ID = 99999 Total Reviews = 5 项目ID = 99999总评论= 5

Thanks! 谢谢!

As mentioned above in the comments, Sean's answer works a treat! 如上面评论中所述,肖恩的答案很有效!

SELECT project_id, COUNT(*) as TotalReviews FROM YourTable GROUP BY project_id 从YourTable GROUP BY project_id中选择project_id,COUNT(*)作为TotalReviews

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM