ranking

MYSQL Select 5 records from one table based on several different values from another

I am by no means fluent in MYSQL. What I am trying to do is I have a table that has a list of Galleries with unique ID numbers. I have another table ImageData that has images that may be as many as 1000 that are related to each GalleryID that is in the first table. I want to do a select that will get 5 random records from each Gallery...

Mysql. Order locations and join listings randomly

I have two tables: locations and listings. locations id title address latitude longitude listings id location info status SELECT locations.title, locations.address, ( 3959 * acos( cos( radians('".$center_lat."') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('".$center_lng."') ) + sin( radians...

how to get mysql ranking among results with same id

Quick question, I have a table of messages each with a timestamp and a reply_id and a topic_id. Reply_ids can be the same as others, which means those messages are in the same group of replies. When I select a reply_id with the min timestamp, meaning it was the first message of that group, I would also like to know its numbered place wit...

Help with MySQL query that is based on the number of clicks on an item

I have a table setup like this (simplified for example): user_id item_id click_dt Each item_id has many user_id's. Basically it's storing the clicks on items, associated to a user_id. I want to query through this and list only the latest user_id for each item_id, based on click_dt. So if there are 5 clicks for item_id 55, the last ...

Python ranking algorithm with 30 levels

I trying find a simple python-based algorithmic ranking system. Here's the scenario: There will be 30 levels, level 1 starts at 0 points. 2000 points are required to achieve level 30. More points will be required as the levels progress. For example, to go from level 1 to 2 might take 3 points. Level 2 to 3 might take 5 additional poi...

Select N records for each category and order by X

I have a database table that contains blog posts. I want to show on the homepage one (or more) post for each category, ordering by date, for example. So my posts table looks like this: id | title | description | cat | filename | date How would I create such a query? I've thought to use group-by or a subselect but I'm not sure if it's ...

PHP sequential numbering

Someone gave me a -1. Not displaying my source code anymore, this has been resolved. ...

are there any web apis out there to maintain online ranking leaderboards?

Hi Im looking for a site that provides leaderboards, via an api. that i can use to keep ranking tables for offline sports, and also if i want to access it via an api to pull in to my blog etc. thanks! ...

Comparison Based Ranking Algorithm

I would like to rank or sort a collection of items (with size potentially greater than 100,000) where each item in the collection does not have an intrinsic (comparable) value, instead all I have is the comparisons between any two items which have been provided by users in a 'subjective' manner. Example: Consider a collection with el...

sql output as a ranking

If I have a table of random values in a sql table, how can I export and display them as a raking rather than the absolute value... for example.. if the three values are 30 85 and 90 how do i get 30 do display as 1 or 1st, 85 as 2 or 2nd etc ...

hacker news algorithm in php?

this is the hacker news ranking algorithm, which i think is a simple way of ranking things, espcially if users are voting on items, but i really dnt understand this, can this be converted to php, so i can understand it fully? ; Votes divided by the age in hours to the gravityth power. ; Would be interesting to scale gravity in a sli...

selecting top N rows for each group in a table

I am facing a very common issue regarding "Selecting top N rows for each group in a table". Consider a table with id, name, hair_colour, score columns. I want a resultset such that, for each hair colour, get me top 3 scorer names. To solve this i got exactly what i need on Rick Osborne's blogpost "sql-getting-top-n-rows-for-a-grouped-...