I am trying to do a simple query that will count the number of reviews for each company in a database table as follows grouped by name
我正在尝试进行一个简单的查询,该查询将计算数据库表中每个公司的评论数量,如下所示按名称分组
e.g reviews table
例如评论表
id company_id review
1 1 Great
2 1 Ok
3 1 Bad
4 2 Nice
So this would return company id 1 with 3, and company id 2 with 1. Any ideas on the easiest solution
因此,这将返回公司ID 1和3,公司ID 2和1.最简单的解决方案的任何想法
2 个解决方案
#1
4
select company_id, count(company_id) from tablename group by company_id
#2
1
try
SELECT company_id,Count(1) FROM reviews GROUP BY company_Id;
#1
4
select company_id, count(company_id) from tablename group by company_id
#2
1
try
SELECT company_id,Count(1) FROM reviews GROUP BY company_Id;