Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Posts
    2

    Unanswered: Using Distinct and SUM in query problem

    Hi,

    I tried the following query and it doesn't work. The 'created' field is in datetime.

    select distinct month(created) as created,
    sum(cost) as total_cost
    from finances
    group by created;

    I want to display the total cost incurred for each unique month. A simple request yet its confusing to make it work.

    Please help

    Regards,
    wayne

  2. #2
    Join Date
    May 2009
    Posts
    258
    Try this instead:
    Code:
    select month(created) as created,
    sum(cost) as total_cost
    from finances
    group by month(created);
    Regards,

    Ax

  3. #3
    Join Date
    Jun 2009
    Posts
    2
    Quote Originally Posted by Ax238
    Try this instead:
    Code:
    select month(created) as created,
    sum(cost) as total_cost
    from finances
    group by month(created);
    Regards,

    Ax
    Cheers Ax , thank you so much! It works now, i just spend a whole day figuring it out..damn i'm a noob

  4. #4
    Join Date
    May 2009
    Posts
    258
    Great to hear! No worries, easy mistake.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •