I am trying to use result value from MySQL avg() function a field in other table, but i dont know how to do it. I was looking for similar questions but i didn't find any.
That's how my database looks like :
books books_ratings
id_book: int(11) id_ragin: int(11) title: varchar(55) id_book: int(11) avg_rating: float rating: int(11) id_client: int(11)
id_book | title | avg_rating
1 ... NULL
2 ... NULL
3 ... NULL
id_rating | id_book | rating | id_client
1 1 5 1
2 1 4 2
3 2 5 1
Im using that query to get the information I want, to use them as fields in "books" table :
SELECT books_ratings.id_book, AVG(books_ratings.rating) AS avg_rating
FROM books_ratings
GROUP BY books_ratings.id_book;
id_book | ang_rating |
1 4.25
2 3.00
How can I use those values to get something like this below ?
id_book | title | ang_rating |
1 ... 4.25
2 ... 3.00
I was trying to use functions in mysql, but i dont know how to use them to get something like this below :
id_book | title | ang_rating |
1 ... 4.25
2 ... 3.00