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
Modify existing query from an unrelated table
문제
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.
해결책
제휴하지 않습니다 StackOverflow