Skip to content
Advertisement

SQL query with Highest value with tie

I am trying to write a query that lists students who have earned the highest total credit in each department. I have to also include tied students in the result. The query should return relation with department name, student name and total credit they earned.

It is giving errors and I don’t know how to deal with ties. If I delete the name part in the query, I have managed to get the highest credits in each department(without a tie)

The table student consists of an ID, name, department, total credit.

Advertisement

Answer

Use RANK() window function:

This is an alternative in case you can’t use window functions:

or with NOT EXISTS:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement