0% found this document useful (0 votes)
87 views1 page

Aperture Assessment

This document contains code to generate rankings of students by their marks. The first query uses a common table expression to join students and marks tables, ranks students by descending marks, and selects the top 10 students. The second query similarly joins and ranks students partitioned by batch, and selects the top 3 students in each batch.

Uploaded by

sourabh sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views1 page

Aperture Assessment

This document contains code to generate rankings of students by their marks. The first query uses a common table expression to join students and marks tables, ranks students by descending marks, and selects the top 10 students. The second query similarly joins and ranks students partitioned by batch, and selects the top 3 students in each batch.

Uploaded by

sourabh sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Answer to ques 1 :-

WITH RankedStudents AS (
SELECT s.name,
m.marks,
ROW_NUMBER() OVER (ORDER BY m.marks DESC) AS rank
FROM students s
INNER JOIN marks m ON s.id = m.student_id
)
SELECT name, marks
FROM RankedStudents
WHERE rank <= 10;

Answer to question 2:-

WITH RankedStudents AS (
SELECT s.name,
s.batch,
m.marks,
ROW_NUMBER() OVER (PARTITION BY s.batch ORDER BY m.marks DESC) AS rank
FROM students s
INNER JOIN marks m ON s.id = m.student_id
)
SELECT name, batch
FROM RankedStudents
WHERE rank <= 3;

You might also like