Ok this is bound to be a long question but it seems pretty simple at heart
so please stick through this long explanation....
I have a file script, and each file is rate-a-ble by the users. I have two
mySQL tables, one for the file listings, and one for the ratings. They look
something like this:
Files
id, file, etc.
Ratings
id, fileid, rating, comment, etc.
Obviously the ratings "fileid" field correlates to the file's id... Anyways,
the ratings field contains a numeric rating unless they are not actually
rating the file - if they are only commenting on the file, the rating field
is a 0. Simple enough...
So now I want to print a list of the files out in a table, and on the table
have a rating column that shows the file's ratings... To do this, I did this
query:
============
SELECT
COUNT(games_ratings.id) AS FIELD_1,
SUM(games_ratings.rating) AS FIELD_2
FROM
games_ratings
WHERE
(games_ratings.rating <> 0)
And then I take field_2 / field_1, round, and voila there's the rating. Now
for the question. This is fine and dandy if I'm sorting the files by id or
whatever, but is it possible to sort the files by their rating, even though
the rating is not a field anywhere in the tables (rather a derived value)?
What would that possible query be? If any more elaboration is needed, please
ask for it.... Thanks a ton!