Re: sql help, please

  • From: Michael Moore <michaeljmoore@xxxxxxxxx>
  • To: Eugene Pipko <eugene.pipko@xxxxxxxxxxxx>
  • Date: Tue, 26 Jan 2010 15:49:12 -0800

or even better ...

SELECT     animal, LTRIM( SYS_CONNECT_BY_PATH( grp, ',' ), ',' ) csv_list
      FROM ( SELECT animal,
                    ROW_NUMBER( ) OVER( PARTITION BY animal ORDER BY 1 )
rnum,
                    grp,
                    COUNT( * ) OVER( PARTITION BY animal ) cnt
              FROM c )
     WHERE rnum = cnt
CONNECT BY animal = PRIOR animal AND   rnum
                                     - 1 = PRIOR rnum
START WITH rnum = 1;

Other related posts: