View Single Post
Old 09-03-2011, 09:16 AM  
camperjohn64
Confirmed User
 
Industry Role:
Join Date: Feb 2005
Location: Los Angeles
Posts: 1,531
MySQL help - I'm stuck

I'm stuck on how to set the popularity / rank for MySQL records.

Let's say I have 10,000 videos, each video has a viewcount. To select them in order of viewcount:

SELECT * FROM videos ORDER BY viewcount;

[0] -> video A with 13,000 views
[1] -> video B with 12,824 views
[2] -> video C with 11,374 views
etc...

But what I want to do, is SET the index for each video based on that sort order so I can retieve it later:

SET video A rank = 0
SET video B rank = 1
SET video C rank = 2
etc...

This way, if I just view video C (mysite.com/video-c.html), I know that it is the 3rd most popular video. I don't want to do an entire SELECT to find out what rank it is in the sort order.

I'm stuck on how to do this in one MysQL statement...
__________________
www.gimmiegirlproductions.com
camperjohn64 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote