Jump to content

Ranking position of a database entry


viciousvinyl

Recommended Posts

Hi,

 

I have a MySQL query which calculates the ranking of an entry within the database, and it works ok, but it gives an inaccurate ranking when the score of an entry is equal to another entry.

 

Select count(*) as ranking, t1.Rank, t1.ID

FROM Database as t1, Database as t2

WHERE t1.Rank <= t2.Rank

 

This counts all entries with a less than or equal score to that of the entry ID in question.

 

However, if there are two or more equal scores then it will count these entries as part of the the count calculation also.

 

e.g.

 

1

2

3

4

4

4 - this is the entry in question.

 

So, there are SIX entries which are less or equal. This is wrong.

 

The ranking of this track is FOUR because it is FOUR equal - the same as the two entries above it.

 

Can someone help me?

 

Thanks.

 

Richard.

Link to comment
https://forums.phpfreaks.com/topic/208849-ranking-position-of-a-database-entry/
Share on other sites

Yes, you didn't understand or I didn't word myself properly.

 

Of course, there's already an index for each record, and each record has an associated score.

 

e.g.

 

Index Score

1        34

2        43

3        14

4        23

5        43

6        43

 

You see, records 2, 5 and 6 have a score of '43', so they are all in fourth place.

 

But the query I'm using registers them all in SIXTH place.

 

Any other suggestions, please let me know.

 

Oh, and I've tried using '<='. This works but not when the record is number 1 ranked.

 

Richard.

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.