DECLARE @Names VARCHAR(8000)
select @Names = COALESCE(@Names + ', ', '') + (S.SubCategoryName+ '|' + CAST(R.RatingValue as varchar(5)))
from dbo.tblQuestions Q
inner join dbo.tblSubCategory S on Q.SubCategoryId=S.SubCategoryId
inner join dbo.tblRatings R on R.QuestionId=Q.QuestionId
inner join dbo.tblReviews RR ON R.ReviewId=RR.ReviewId
INNER JOIN dbo.tblCompanies C ON C.CompanyId=RR.CompanyId
where C.CompanyId=7
如何对评级值求和?
答案 0 :(得分:0)
评价什么?您想获得指定公司的所有评级值的总和吗?
如果是这样,试试这个:
select @Names = COALESCE(@Names + ', ', '') + (S.SubCategoryName+ '|' + CAST(R.RatingValue as varchar(5))),
SUM(R.RatingValue) as ratingSum
from dbo.tblQuestions Q
inner join dbo.tblSubCategory S on Q.SubCategoryId=S.SubCategoryId
inner join dbo.tblRatings R on R.QuestionId=Q.QuestionId
inner join dbo.tblReviews RR ON R.ReviewId=RR.ReviewId
INNER JOIN dbo.tblCompanies C ON C.CompanyId=RR.CompanyId
where C.CompanyId=7
group by C.CompanyId