我有两张桌子Company
和CompanyLike
公司赞
- ID
- 评级之星
- 数数
- 公司编号
Company 和 CompanyLike 有1 to Many
关系。一家公司可以有很多赞
像桌子一样的公司看起来像这样
+----------------------------+
| ID RatingStar Companyid |
+----------------------------+
| 1 5 5636 |
| 2 5 5636 |
| 3 1 101 |
| 4 2 959 |
+----------------------------+
现在我想计算 RatingStar 的次数5
,以及它对2
每个Companyid 的次数
我目前的工作是
SELECT RatingStar AS RatingStar,com.id AS Companyid , c.Id AS Id ,
com.Name AS CompanyName, Count(RatingStar) AS ratingCount
FROM CompanyReviewLike AS c
INNER JOIN Company AS com ON com.id = c.Companyid
GROUP BY RatingStar ,com.Name , com.id ,c.Id