I'm using Oracle XE 10g.
Please I beg you to read my question carefully. I have a weird use case for this but please bear with it.
Let's say I have the following records:
Table person
Name YearOfBirth
a null
a 2001
a 2002
b 1990
b null
c null
c 2001
c 2009
Basically if I do the following query:
select
p.Name, max(p.YearOfBirth)
from
person p
group by
p.Name
That will give me records with distinct Names and each distinct name will be paired to maximum value of YearOfBirth within its group. In the given example the group where Name='a', the maximum YearOfBirth is 2002.
If max() is an aggregate function that returns the maximum value of a column in a given group, is there a function that returns the first value within the group that is not null? Instead of giving me the maximum value, I want the first value you could find as long as it is not null.
Please don't ask me why I can't simply use min() or max() instead.
Obviously I can't use rownum here as some might suggest because doing so will limit the number of groups I could get.