SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    US
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Performing addition on rows

    I have the following rows in my table:

    name sale1 sale2 sale3

    the employees record their daily sales in this table. lets say i wanted to add all the sales for each employee how do i go about performing addition on these rows... i know how to do the select statement to get the sum of the sales, but not do something to the extent of:

    totsales=sum(sale1)+sum(sale2)+sum(sale3) ---> this is what i'm trying to achieve. what's the best possible way to do this.
    thanks for any replies.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select name, sale1+sale2+sale3 as total_sales
      from yourtable
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    US
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you so much! i'll give it a shot as soon as i'm back on the server.


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
  •