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!

Need help with group by query

Discussion in 'SQL PL/SQL' started by spydeyk, Apr 2, 2013.

  1. spydeyk

    spydeyk Guest

    I need a group by query as follows

    Table
    Name Cat1 Amount
    ------- ----- ---------
    Mark A 100
    Tony A 256
    Jhon B 988
    Ruben 333
    Hazel C 2222
    Angel 111


    I am trying to use group by on Cat1, here is what i get
    Cat1 Count(*)
    ------ ---------
    A 2
    B 1
    C 1
    (null) 2


    Expected result:

    Cat1 Count(*)
    ------ ---------
    A 2
    B 1
    C/null 3


    Basically I would like to combine C and null Cat1.

    Please help me with this.
     
  2. sambuduk

    sambuduk Forum Advisor

    Messages:
    242
    Likes Received:
    73
    Trophy Points:
    455
    Location:
    Hyderabad , Telangana
    Hi

    Use the below query.

    select NVL(Cat1,'C') , count(*) from XX_TAB2
    group by NVL(Cat1,'C')

    output
    --------
    NVL(CAT1,'C') COUNT(*)
    -------------- --------
    A 2
    B 1
    C 3




    Regards
    Samba