Answered Questions

  • Sql query to obtain 2nd highest mark in each subject for a student

    Given a table with 3 columns StudentName,Subject and Marks.Write a sql to retrieve second highest Marks Obtained for each student.

    SANTHOSH KUMAR GUJJA

    • Nov 25th, 2017

    SEL STUDENTNAME,MARKS FROM TABLE
    QUALIFY ROW_NUMBER() OVER(PARTITION BY STUDENTNAME ORDER BY MARKS DESC)=2

    Rakesh

    • Aug 23rd, 2016

    Try to avoid row_number while solving this kind of data because you will get wrong data when the starting record are duplicate. Try to use dense_rank