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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.