#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    SQL Sub query help


    Hi Folks,

    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.

    Cheers,

    Henrik
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,928
    Rep Power
    378
    What have you got so far?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    Hi,

    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=..
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,928
    Rep Power
    378
    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...
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    Thanks that worked perfectly.

IMN logo majestic logo threadwatch logo seochat tools logo