SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sum of 2 columns

    Hello,

    Is it possible to query the sum of 2 columns into 1 result?

    something like the following but only returns a single result:
    $sql= "select name, sum(col1), sum(col2) from table group by name order by sum(col1)+sum(col2) DESC"
    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2009
    Location
    Austria
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT SUM(col1)+SUM(col2) AS summary ... ORDER BY summary DESC;

    should work ... i hope so

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by blubb View Post
    SELECT SUM(col1)+SUM(col2) AS summary ... ORDER BY summary DESC;

    should work ... i hope so
    Did work, perfect, that was easy thanks...


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
  •