Jump to content


Photo

query help


  • Please log in to reply
2 replies to this topic

#1 a2bardeals

a2bardeals
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationAnn Arbor, MI

Posted 12 June 2006 - 09:33 PM

i am trying to create a top ten script for a MySQL ratings system
the query works near perfectly but with one flaw. it wont put the damn things in order.
it returns only ten of the highest rated.
it groups the individual ratings from all cells where the article #'s are the same and averages them.
but the ORDER BY doesn't seem to be working how i would like it to.

query looks like this:
mysql_query("SELECT article, AVG(rate) FROM ratings GROUP BY article ORDER BY rate DESC LIMIT 10");


i belive my problem is in the order by becuase it doesn't order by the average rating and when i try:

mysql_query("SELECT article, AVG(rate) FROM ratings GROUP BY article ORDER BY avg(rate) DESC LIMIT 10");

i get errors.

any ideas?

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 12 June 2006 - 09:41 PM

Try: SELECT article, AVG(rate) as rate FROM ratings GROUP BY article ORDER BY rate DESC LIMIT 10
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 a2bardeals

a2bardeals
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationAnn Arbor, MI

Posted 12 June 2006 - 11:19 PM

thanks that worked perfectly...its always something small it seems




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users