Results 1 to 6 of 6

Thread: thougt ilshi

  1. #1
    Join Date
    Feb 2011
    Posts
    3

    Unanswered: thougt ilshi

    Hi All
    Can multiple group by clause be used in single query. The requirement is to have a group by on three combinations . I have a table with composite keys
    Say A,B,C ,
    The group by's have to done on
    1] A,B
    2] A,C
    3] A

    Can it be done using single query, or three different queries have to be done for three combinations.
    Please advice

  2. #2
    Join Date
    Aug 2008
    Location
    Toronto, Canada
    Posts
    2,367
    possibly "group by grouping sets ... "

  3. #3
    Join Date
    Feb 2011
    Posts
    3

    entribi Consulting

    Thanks for the reply

    i tried this query but it results in error

    SELECT ER_NBR, INSTR_ID, sum( STRT_INSTR_PRICE ) AS pris
    FROM MATB252
    GROUP BY GROUPING
    SETS(( ER_NBR ))


    DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: SETS;UNION

    Any idea .

  4. #4
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    are you on mainfraame? of luw?

    what db2 version are you on?
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  5. #5
    Join Date
    Feb 2011
    Posts
    3
    Its Unix ,DB2 7.2

  6. #6
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    Code:
    SELECT ER_NBR, INSTR_ID, sum( STRT_INSTR_PRICE ) AS pris
    FROM MATB252
    GROUP BY GROUPING
    SETS(( ER_NBR ))
    In this example, try including instr_id in the grouping sets.
    Visit the new-look IDUG Website , register to gain access to the excellent content.

Posting Permissions

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