문제

I have this query:

SELECT * FROM COMPANY_INFORMATION, ADDRESS WHERE ADDRESS.ID = COMPANY_INFROMATION.ID;

That gets the address and company information from two tables.

In addition I have a table called REVIEWS that have 3 columns ID, RATING(int), REVIEW(TEXT).

Is it possible to modify the existing query to get the number of ratings and average ratings in one query call.

I know of the COUNT(*) and AVG(RATING) methods, but i don't want to make 2 or 3 SQL calls.

Thank you for any one that can help.

도움이 되었습니까?

해결책

SELECT c.*, a.*, count(r.rating) as total, AVG(r.rating) as average
FROM COMPANY_INFORMATION c 
inner join ADDRESS a on a.id = c.id
inner join REVIEWS r on r.id = c.id
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top