php - Getting average in MySQL -


i have question using mysql. have 2 tables, 1 names of games , 1 different ratings games. want able search game name , see average ratings each game. far kind of managed average rating, see rating of 1 game instead of multiple entries. here's query far:

select games.name, cast(avg(reviews.rating) decimal(6, 1)) average_rating     games     join reviews     on games.id = reviews.game     games.name '%spider%'     , type = '7'     , rating != 0 

i hope of smart people can me out this! thanks, robert

you have use group by clause on proper field average each group, otherwise calculate average of all rows. guess it's games.id, depends on table schemata.

select games.name, cast(avg(reviews.rating) decimal(6, 1)) average_rating games join reviews on games.id = reviews.game games.name '%spider%' , type = '7' , rating != 0 group games.id; 

read more called aggregate functions


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -