Ok this should be easy so I'm prolly going to screw it up, but here goes =D

Your query should be:
SELECT UserID, SUM(points) FROM History WHERE WeekID = 'whatever' GROUP BY
UserIdI think that should do it. Someone yell if its wrong though.

-Nick

> I have 2 tables
>
> Users (UserID)
>
> History (UserID, WeekID, Points)
>
> When a User record is created a record is inserted into History with
> the current WeekID, so for example data could be :
>
> Users
> --------
> 1111
> 2222
> 3333
> 4444
>
> History
> ----------
> 1111 - 1 - 10
> 2222 - 1 - 20
> 3333 - 1 - 30
> 4444 - 2 - 40
>
> I want to run a query to return one row for each User row and their
> points for any given week.  In other words somebody asks for all points
> in Week 1 the result should be :
>
> 1111 - 10
> 2222 - 20
> 3333 - 30
> 4444 - 0
>
> Or, all points for WeekID 2 would give :
>
> 1111 - 0
> 2222 - 0
> 3333 - 0
> 4444 - 40
>
>
> I have tried lots of things but I think my brain is just not giving me
> the correct solution.
>
> Please help!
>
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>   http://www.mysql.com/manual.php   (the manual)
>   http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]> To
> unsubscribe, e-mail
> <[EMAIL PROTECTED]> Trouble
> unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to