I'm trying to figure out a solution to a query.
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). 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'.
I can't figure out how to echo in the following way:
Project ID = 11122 Total Reviews = 2
Project ID = 99999 Total Reviews = 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.