Tricky math SQL statement
| From: | Merlin | Date: | Sun, 20 Apr 2003 08:16:48 +0000 |
| Subject: | Tricky math SQL statement | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-27187@lists.php.net to get a copy of this message | ||
Hi there,
I have a tricky SQL statement which I would like to put on a MySQL 3.X DB
Not sure if this workes out with a simple statement, thats why I post it
into the php.db newsgroup. Might require some php?!
--------
OK... short description:
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.
--------
This requires some calculation within the db, as far as I know this should
be possible, but this seems a bit to complex. I tryed some statements, but
failed ;-((
Something like:
SELECT DISTINCT
user_id
FROM
table
WHERE
MAX (SUM(points))
ORDER BY
timestamp
LIMIT
3
Thank you for any help on this. I am not a SQL expert, so I am having a real
hard time on that one.
Cheers, Merlin