SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Query Question

    Hello MySQL Gurus,

    I have a simple query question.

    For the sake of simplicity, let's imagine this is my table of results.

    user_id amount
    1 20
    1 24
    2 32
    3 55








    When I output this data using a while or foreach loop, how can I merge the rows that have the same user_id and also add it's amount to one value. So it displays something like this:

    1 Total amount: 44
    2 Total amount: 24
    3 Total amount: 55

    Thank you

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    use SUM() and GROUP BY

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •