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!

Aggregate data with nulls and duplicate values (chpt.2)

Carl COct 4 2018 — edited Oct 4 2018

Hi,

I've this issue and I hope you can help.

Thanks to Mathguy and Paulzip, I could solve fisrt issue with this dataset.

Nevertheless, after adding a new column "Town" into my selection I got a wrong result again with duplicate values

   

IDNameSurnameBirthdaytownMy comments
1000AAABBB19000101Frankfurt
1000AAABBBNullnullDiff brthday
1000AAABBB19201006London
2000HHHGGGnullNullBirthday Not available
3000MMMRRRnullnull
3000MMMRRR19620723null
4000TTTJJJnullDelhi
4000TTTJJJ20010801DelhiTwins
4000SSSYYY20010801DelhiTwins

I was expecting this result

   

ID Name SurnameBirthdayTown
1000AAABBB19000101Frankfurt
1000AAABBB19201006London
2000HHHGGGnullBogota
3000MMMRRR19620723Null
4000TTTJJJ20010801Delhi
4000SSSYYY20010801Delhi

Instead i'm getting result below :

   

idnamesurnamebirthdaytown
1000AAABBB19000101Frankfurt
1000AAABBB19201006London
1000AAABBBNullnull
2000HHHGGGnullBogota
3000MMMRRR19620723null
3000MMMRRRnullnull
4000SSSYYY20010801Delhi
4000TTTJJJ20010801Delhi
4000TTTJJJnullDelhi

I've used same query provided by @"mathguy", which was really helpfull

select   distinct id, name, surname,

         nvl(birthday, max(birthday) over (partition by id, name, surname)) as birthday

from     sample_data

order by id, name, surname, birthday -- if needed

;

But it's not retrieving the good results when adding new data.

I've tried using min(id) ... and regroup but nothing change

If anyone can help, that would be great

regards

Carlos

PS

Attached file the script to create dataset.

Oracle Version 11g2

This post has been answered by mathguy on Oct 4 2018
Jump to Answer
Comments
Post Details
Added on Oct 4 2018
11 comments
1,118 views