| SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it. |
|
|||
The top x most popular whatever?One table contains photos (paths to files that is), and one contains rating data on how much people like the pictures.
simplified.. photo: pid | name | path 777 | lucky | folder/filename.jpg photo_has_rating: pid | voteValue | date 777 | 5 | unixDate 777 | 3 | unixDate 777 | 1 | unixDate Now I want to select the most popular files (limit x), and the most popular files the last week (limit x). I'll have to count the voteValues and find the top x popular, and then join with photo, and get the names and paths.. |
|
|||
|
The x most popular ever would be something along the lines:
SELECT t1.name, sum(t2.voteValue) AS totalVotes FROM photo AS t1If you wanted the the result for the last week you would have to use a WHERE clause |