SUM for multiple colums
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: SUM for multiple colums

  1. #1
    Join Date
    May 2004
    Location
    Central FL
    Posts
    12

    SUM for multiple colums

    Hello folks, I'm new here, I'm actually a Java guy who is doubling as a database programmer for now...

    So...I have a table called Funds and columns are Q1, Q2, Q3, Q4, and funds_id (this is psuedo of course). So I need to get the total of all these, like I need to do this:

    select (Q1 + Q2 + Q3 + Q4) as yearly_total
    where funds_id = 'XXX'

    something like that.

    So how would I do that? Would I want to build a view? Thanks.

    Edit: what I meant was, how would I use the SUM function, or could I just do it using the + symbol?

  2. #2
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    depends on what you want to do...
    Code:
    SQL> select * from xyz;
    
            ID          X          Y          Z
    ---------- ---------- ---------- ----------
             1          1          2          3
             2          4          3          2
             3         10         11         12
            10          1          2          7
    
    SQL> select x+y+z from xyz where id=1;
    
         X+Y+Z
    ----------
             6
    
    SQL> select x+y+z from xyz where id=3;
    
         X+Y+Z
    ----------
            33
    
    SQL> select sum(x+y+z) from xyz where id in (1,3);
    
    SUM(X+Y+Z)
    ----------
            39
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

  3. #3
    Join Date
    May 2004
    Location
    Central FL
    Posts
    12
    Thanks alot, that was the answer I was looking for.

Posting Permissions

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


Click Here to Expand Forum to Full Width