Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how I can change this query to group correctly

896976Sep 5 2013 — edited Sep 5 2013

This query return the right results for an individual pidm, (SPRIDEN_PIDM = 42306) but not when I run it for all the pidms in the table

I get something like this which is fine,

42306Z007178502
42306Z006300151
42306Z008226473

I want to be able to comment it out the   (SPRIDEN_PIDM = 42306) and got the same results for each pidm

like 

42306Z007178502
42306Z006300151
42306Z008226473
42807Z007178502
42807Z006300151
42807Z008226473

etc..etc.. it seems that is not grouping correctly

SELECT

         SPRIDEN_PIDM,

        SPRIDEN_ID,

            ROWNUM

           FROM (SELECT SPRIDEN_PIDM,

         SPRIDEN_ID,

      ROW_NUMBER ()

               OVER (PARTITION BY sPRIDEN_pidm ORDER BY  SPRIDEN_ID DESC) --- test_date DESC)

                             rn      

              FROM (SELECT    SPRIDEN_PIDM,

                                  SPRIDEN_ID

                                  FROM SPRIDEN

                                  WHERE SPRIDEN_ID LIKE 'Z%'

                                 AND SPRIDEN_PIDM = 42306

                                  GROUP BY

                                     SPRIDEN_PIDM ,

                                       SPRIDEN_ID ))

                              GROUP BY SPRIDEN_pidm,SPRIDEN_ID,ROWNUM

                              having ROWNUM >= 1

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 3 2013
Added on Sep 5 2013
2 comments
325 views