Skip to content
Advertisement

Tag: row-number

SQL find the 2 highest score for each country

I have two tables: maps_query and map_time like below: The question is to find the 2 highest score for each country. Desired output is like below: I was trying to use row_number() over but don’t know how to complete the query. Answer This can be achieved by rank() instead of row_number(). A good reference article: https://spin.atomicobject.com/2016/03/12/select-top-n-per-group-postgresql/

Creating a row number column based on another columns value

I have the following data: it’s a calendar that has date and year/week number there week is our internal calendar. what i want to do is sort by the most recent week number and have that be rel_week_index=1, and then the previous week be rel_week_index=2, etc. I got this to work by doing ROW_NUMBER() OVER(PARTITION BY YEAR ORDER BY YEAR

SQL Server Grouped Number Generation

I need a way in a SQL Server query to generate grouped numbers when the data switches from one specific data value to another. Based on the first two columns below and how they are ordered, how can the query generate the numbers in the third column? When the Type column changes from Prim to anything else, all the records

Advertisement