Jump to content

help writing sql statement using AVG and a JOIN


n8w

Recommended Posts

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

rating.jpg\" border=\"0\" alt=\"IPB Imag

 

I need help writing a sql statement in order to get the score of each illustrator.

 

I have two tables

 

votesql.gif\" border=\"0\" alt=\"IPB Ima

 

How do I write a sql statement that will join the tables and get the average of each illustrator's score?

 

thanks!!!!!!

Link to comment
Share on other sites

[!--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

rating.jpg\" border=\"0\" alt=\"IPB Imag

 

I need help writing a sql statement in order to get the score of each illustrator.

 

I have two tables

 

votesql.gif\" border=\"0\" alt=\"IPB Ima

 

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--]

Link to comment
Share on other sites

[!--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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.