Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2012
    Posts
    37

    Unanswered: How to sum up row data in sql query

    Hi All

    I am trying to sum up the row query in single SQL query like

    COLA<-->COLB<-->COLC<-->COLD<-->COLE
    1<--><-->9<-->0<-->1
    <-->0<-->9<-->0<-->1
    1<-->0<-->10<-->9<-->1
    <--><--><--><-->

    So the expected result wanted is

    Result
    11
    10
    21
    0

    Thanks

  2. #2
    Join Date
    Mar 2012
    Posts
    37
    guys any luck...

  3. #3
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    This link should get you started: http://bit.ly/1dgi3Fe
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    likely would benefit from URL below

    Oracle Database Search Results: nvl
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Mar 2012
    Posts
    37
    Both above link doesn't worked for me.

  6. #6
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Quote Originally Posted by goodman2253 View Post
    Both above link doesn't worked for me.
    What queries did you tried?

    What were the problems in the results of your tried queries?

  7. #7
    Join Date
    Jul 2011
    Location
    Nasik, Maharastra
    Posts
    34
    With the use of NVL function, we can find-out total as per your requirement.

    create table demo(a number, b number, c number);
    insert into demo values(1,1,1);
    insert into demo values(NULL,1,1);
    insert into demo values(NULL,1,NULL);

    select nvl(a,0) a, nvl(b,0) b, nvl(c,0) c, nvl(a,0) + nvl(b,0) + nvl(c,0) as "Total" from demo;

    It will show you the exact result as you want.
    SHARING KNOWLEDGE IS ULTIMATE KEY TO GAINING KNOWLEDGE...
    dbatricksworld.com

  8. #8
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    IMO, it does not appear to me that the table in the example conforms to Third Normal Form.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

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