Answered Questions

  • To get second highest age from the student table

    I am trying to get second highest age from the student table.Student table:SQL> desc student; Name Null? Type ----------------------------------------- -------- ----------------- ROLLNO NUMBER NAME VARCHAR2(20) AGE NUMBERAnd...

    Sunil Badam

    • Jan 29th, 2016

    We can use rank function with partition by. It is very simple to use.

    Code
    1. SELECT * FROM (SELECT NAME,ROLLNO,AGE,
    2. RANK() OVER (PARTITION BY STUDENT.ROLLNO ORDER BY STUDENT.AGE DESC)AS RANK
    3. FROM TABLE.STUDENT)
    4. WHERE RANK=2;

    Neeraj

    • Jan 7th, 2016

    Code
    1. SELECT max(age)
    2. FROM student
    3. WHERE age < (SELECT max(age)
    4.                 FROM student);