sql server - SQL Selecting average of rating from another table -


i have 2 tables: anime_list , anime_reviews.

anime_list table has 'rating' field grabs average rating anime_reviews. however, ratings (rows) don't exist in anime_reviews , current query returns titles have average rating.

select anime_list.animeid, anime_list.name, anime_list.animeimage, anime_list.synopsis, anime_list.type, anime_list.episodes, anime_list.genres, avg(anime_reviews.rating)  anime_list inner join anime_reviews on anime_list.animeid = anime_reviews.animeid group anime_list.animeid, anime_list.name, anime_list.animeimage, anime_list.synopsis, anime_list.type, anime_list.episodes, anime_list.genres 

how return value of 0.0 if there no ratings (rows) in anime_reviews each title listed in anime_list?

thanks help!

enter image description here

a version using subquery

select l.animeid,         l.name,         l.animeimage,         l.synopsis,         l.type,         l.episodes,         l.genres,         (select isnull(avg(rating), 0) rating           anime_reviews           animeid = l.animeid)   anime_list l 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -