Skip to content
Advertisement

Sql Query / Calculate rank for values based on date and id

For each date and id we have to give the rank to values in decreasing order.

Below is the Input Table.

Output should look like below:

Advertisement

Answer

You can use RANK(), partitioning on date and id and ordering by value descending:

Output:

Demo on SQLFiddle

This query will run on all the DBMS you have tagged your question with.

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