Re: Tricky math SQL statement
| From: | Ronan Chilvers | Date: | Sun, 20 Apr 2003 14:59:19 +0000 |
| Subject: | Re: Tricky math SQL statement | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27195@lists.php.net to get a copy of this message | ||
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