I want to create a view who gives me the grandchildren of the oldest person who has some. And the problem is that I can't find a way to translate in sql the phrase : "who has some".
I work in only one table which is pretty basic :
Person : number(type number), lastname, firstname, dateofbirth, gender, mother(type number), father(type number).
This is what I tried to do :
I tried to create a view who gives me the oldest person who has grandchildrens (but this is not what is done here)
CREATE OR REPLACE
VIEW oldestone
AS SELECT number FROM persons
WHERE (sysdate-dateofbirth)/365 >= ALL
(SELECT (sysdate-dateofbirth)/365 FROM persons)
AND EXISTS (SELECT * FROM persons
WHERE level=3
START WITH number = number
CONNECT BY PRIOR number = father OR PRIOR numero = mother);
And with the number of the first view I can get the grandchildren :
CREATE OR REPLACE
VIEW grandchildren
AS SELECT firstname,lastname FROM persons
WHERE level=3
START WITH number = (SELECT number FROM oldestone)
CONNECT BY PRIOR number = father OR PRIOR number = mother;
The problem is I know I'm not translating : the grandchildren of the oldest person who has some. Because in my first view when i wrote number = number I want to refer to the number of my select clause line 3 but i know it's not the case.
Thanks in advance for you help guys !
Chris.