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!

GROUP BY NULL values

866081May 6 2016 — edited May 9 2016

I have query which works fine for all my requirements apart from the below scenario

For a particular ID, based on the FST_NM, MDL_NM, LST_NM and SFX_NM combination which ever is occurring frequently then those should be pulled. In the below case when all the names are not null then that values should be pulled but right now the query is pulling FST_NM as TES , MDL_NM as TAM , LST_NM as Null and SFX_NM as NULL.

Actually it should  be TES, TAM, BAM, SET.

It would be helpful if you can help me to acheive this.

 

IDFST_NMMDL_NMLST_NMSFX_NM
1TESTAMBAMSET
1TESTAM
1TESTAM
1TESTAM


SELECT FST_NM,

MDL_NM,

LST_NM,

SFX_NM,

ID

FROM (SELECT ID,

UPPER(TRIM(FST_NM)) FST_NM ,

UPPER(TRIM(MDL_NM)) MDL_NM,

UPPER(TRIM(SFX_NM)) SFX_NM,

UPPER(TRIM(LST_NM)) LST_NM,

ROW_NUMBER () OVER ( PARTITION BY  ID

                                           ORDER BY      COUNT (*)    DESC

                                          ) AS TRANK

FROM TEST

GROUP BY ID,UPPER(TRIM(FST_NM)),

UPPER(TRIM(MDL_NM)),

UPPER(TRIM(SFX_NM)),

UPPER(TRIM(LST_NM)))

WHERE TRANK=1

Thanks

This post has been answered by CarlosDLG on May 6 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2016
Added on May 6 2016
8 comments
3,446 views