November 6th, 2012, 04:16 AM
SQL Sub query help
I am having problems building the right SQL query:
I have a table with following structure:
Date, username, points.
I would like to find out the sum of the points each username has reached in a month.
Any help is greatly appreciated.
November 6th, 2012, 04:46 AM
What have you got so far?
November 6th, 2012, 04:55 AM
I have so far
Select username, sum(points) from table1 where username = any(select distinct(username) from table1 where month(date)='11' and year(date)='2012')
But I am getting syntax error next to username=..
November 6th, 2012, 05:00 AM
Well I'm not going to give the answer straight out but I'd expect to see the following in there, and not much else...
SELECT username, DATE_FORMAT(...), SUM(...) FROM ... GROUP BY...
November 6th, 2012, 05:15 AM
Thanks that worked perfectly.