SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2005
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    grouping dates together then sum()

    Can anyone show me how to add the amounts together but by month. So all the month's of 12's added to gether and all the 11's (months).




    mysql> select * from date;
    +----+------------+---------+
    | id | date | amount |
    +----+------------+---------+
    | 1 | 2006-12-25 | 100.00 |
    | 2 | 2006-12-20 | 1456.34 |
    | 3 | 2006-11-04 | 400.00 |
    +----+------------+---------+
    3 rows in set (0.00 sec)

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select month(date) as mth
         , sum(amount) as total_amt
      from daTable
    group
        by mth
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2005
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much. Man i got close a couple times. I was using the month() function and the AS key work as well as GROUP BY. BUt as you know almost in horse shoes and coding sometimes just deosn't cut it!!!! Thanks for the help. Happy Holidays and Merry X mas


Bookmarks

Posting Permissions

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