Re: Tricky math SQL statement

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

 



"Merlin" <news.groups@web.de> wrote in message
20030420081645.66500.qmail@pb1.pair.com">news:20030420081645.66500.qmail@pb1.pair.com...
> Hi there,
>
> I have a tricky SQL statement which I would like to put on a MySQL 3.X DB

I have no experience with 3.x; I can tell you
how I would do it on 4.x and you will have to
adapt it as needed.


> 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.

SELECT user_id, SUM(points) AS total
FROM table
GROUP BY user_id
WHERE timestamp > date_sub(NOW(), INTERVAL 7 DAYS)
ORDER BY total DESC
LIMIT 3




-- 
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