n8w Posted January 6, 2006 Share Posted January 6, 2006 How do I write a sql statement that will join the tables and get the average of each illustrator's score? I'm trying to create a rating system where users can rate multiple illustrators on one page and it shows the illustrator's existing score I need help writing a sql statement in order to get the score of each illustrator. I have two tables How do I write a sql statement that will join the tables and get the average of each illustrator's score? thanks!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/3156-help-writing-sql-statement-using-avg-and-a-join/ Share on other sites More sharing options...
obsidian Posted January 6, 2006 Share Posted January 6, 2006 [!--quoteo(post=334030:date=Jan 6 2006, 11:10 AM:name=n8w)--][div class=\'quotetop\']QUOTE(n8w @ Jan 6 2006, 11:10 AM) 334030[/snapback][/div][div class=\'quotemain\'][!--quotec--] How do I write a sql statement that will join the tables and get the average of each illustrator's score? I'm trying to create a rating system where users can rate multiple illustrators on one page and it shows the illustrator's existing score I need help writing a sql statement in order to get the score of each illustrator. I have two tables How do I write a sql statement that will join the tables and get the average of each illustrator's score? thanks!!!!!! try this: [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] a.illustrator_id, AVG(score) AS avg FROM illustrator_table a RIGHT JOIN score_table b ON a.illustrator_id = b.illustrator_id GROUP BY a.illustrator_id; [!--sql2--][/div][!--sql3--] Quote Link to comment https://forums.phpfreaks.com/topic/3156-help-writing-sql-statement-using-avg-and-a-join/#findComment-10693 Share on other sites More sharing options...
n8w Posted January 6, 2006 Author Share Posted January 6, 2006 [!--quoteo(post=334045:date=Jan 6 2006, 02:07 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Jan 6 2006, 02:07 PM) 334045[/snapback][/div][div class=\'quotemain\'][!--quotec--] try this: [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] a.illustrator_id, AVG(score) AS avg FROM illustrator_table a RIGHT JOIN score_table b ON a.illustrator_id = b.illustrator_id GROUP BY a.illustrator_id; [!--sql2--][/div][!--sql3--] THANKS SOOOOOOOOOOOOOOOOOO MUCH!!!!!! This is awesome ..sorry about the double posts .. I wasn't sure if this forum got much traffic so I posted it in the general .. thanks Quote Link to comment https://forums.phpfreaks.com/topic/3156-help-writing-sql-statement-using-avg-and-a-join/#findComment-10703 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.