1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Advanced Sum in select statment

Discussion in 'SQL PL/SQL' started by Mohamed_Khateeb, Mar 11, 2014.

  1. Mohamed_Khateeb

    Mohamed_Khateeb Active Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    55
    PROJECT Code NET
    111031 110104 900
    111031 110301 240
    111031 111208 405,071
    111031 111301 260
    111031 120201 3,255
    111031 120202 857,090
    111031 120301 4,580,333
    111031 120306 21,840
    111031 130100 10,903
    111031 170105 64,650
    111031 312000 50


    I need to select project in one row and show new column (Group A) as sum (Net) where code in (120201','120301') and another new column (Group B) as sum for rest of codes
    as

    PROJECT Net groub A Net groub B
    111031 4,583,588 1,361,004

    any help please
     
  2. jagadekara

    jagadekara Forum Guru

    Messages:
    1,126
    Likes Received:
    145
    Trophy Points:
    1,805
    Location:
    Pulivendula
    Hi check below Query, It may help you....

    Code (SQL):
    SELECT a.project,SUM(a.net) net_group_A,(SELECT SUM(b.net) net_group_A
                                         FROM xx_project_code_net  b
                                         WHERE b.code NOT IN ('120201','120301')
                                         AND a.project=b.project
                                         GROUP BY b.project) net_group_B
    FROM xx_project_code_net a
    WHERE a.code IN ('120201','120301')
    GROUP BY a.project;
     
    Mohamed_Khateeb likes this.
  3. Mohamed_Khateeb

    Mohamed_Khateeb Active Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    55
    Thanks a lot it worked with me