我有以下表格:
this.pictureBoxWarning.Image = System.Drawing.SystemIcons.Warning.ToBitmap();
+--------+ +----------------+ +------------+
| Rating | | Rating_Person | | Person |
+--------+ +----------------+ +------------+
| ID | | RAT_ID | | ID |
| RATING | | PER_ID | | AVE_RATING |
+--------+ +----------------+ | NO_RATINGS |
+------------+
可以包含多个Person
。
我有一个SQL查询,我得到一个Ratings
列表:
Persons
问题:
如何加入SELECT * FROM PERSON
表格以填充Rating
和AVE_RATING
值?
我可以对NO_RATINGS
表执行以下操作,但如何计算JOIN
和AVE_RATING
?
NO_RATINGS
感谢您的帮助。
(我正在使用MySQL)
答案 0 :(得分:0)
解决方案:
SELECT
count(R.ID) as NO_ROWS, avg(R.RATING) as AVE_RATING,
P.* FROM PERSON P
INNER JOIN rating_person RP ON P.ID = RP.PER_ID
INNER JOIN RATING R ON RP.RAT_ID = R.ID
group by P.ID