Thursday, December 25, 2008

treeview in oracle

select LEVEL,ID,NAME,REPORT_TO
from top_dogs
START WITH report_to IS NULL
CONNECT BY PRIOR id=report_to

select LPAD(NAME,length(NAME)+LEVEL*2,'_')
from top_dogs
START WITH report_to IS NULL
CONNECT BY PRIOR id=report_to

Monday, December 22, 2008

top-n Analysis in oracle

select * from (select * from top_dogs order by salary DESC)where ROWNUM<=3
top 3 salary earners