Re: Tricky math SQL statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Merlin

Comments inline ...

On 20 Apr,2003 at 10:16 Merlin Merlin wrote:

<snip>> 
> tablelayout:
> timestamp user_id points
> 
> The goal is to get out of this table the top 3 users which have acchieved
> the most points in the last 7 days.
> --------
</snip>

If I've understood the situation correctly, what about something like...

SELECT user_id AS 'User', SUM(points) AS 'Score' 
FROM table 
GROUP BY user_id
ORDER BY timestamp, Score DESC
LIMIT 3

So, create a list of the total points for each user, ordered first by date and then Score desc (top ones first) ... oh, and limit it to the first 3 records...

Does this do it ?

-- 
Ronan
e: ronan@thelittledot.com
t: 01903 739 997
w: www.thelittledot.com

The Little Dot is a partnership of
Ronan Chilvers and Giles Webberley

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux