Questions tagged [rank]

Rank refers to the relative position, value, worth, complexity, power, level etc. of an object.

Rank refers to the relative position, value, worth, complexity, power, importance, authority, level etc. of a person or object (source).

From Wikipedia:

In computer programming, rank with no further specifications is usually a synonym for (or refers to) "number of dimensions"; thus, a bi-dimensional array has rank two, a three-dimensional array has rank three and so on. Strictly, no formal definition can be provided which applies to every programming language, since each of them has its own concepts, semantics and terminology; the term may not even be applicable or, to the contrary, applied with a very specific meaning in the context of a given language.

1637 questions
331
votes
27 answers

ROW_NUMBER() in MySQL

Is there a nice way in MySQL to replicate the SQL Server function ROW_NUMBER()? For example: SELECT col1, col2, ROW_NUMBER() OVER (PARTITION BY col1, col2 ORDER BY col3 DESC) AS intRow FROM Table1 Then I could, for example, add a…
Paul
  • 16,285
  • 13
  • 41
  • 52
175
votes
14 answers

Rank function in MySQL

I need to find out rank of customers. Here I am adding the corresponding ANSI standard SQL query for my requirement. Please help me to convert it to MySQL . SELECT RANK() OVER (PARTITION BY Gender ORDER BY Age) AS [Partition by Gender], …
Aadi
  • 6,959
  • 28
  • 100
  • 145
110
votes
3 answers

Number rows within group in increasing order in a pandas dataframe

Given the following dataframe: import pandas as pd import numpy as np df = pd.DataFrame({'A': ['A','A','A','B','B','B'], 'B': ['a','a','b','a','a','a'], }) df A B 0 A a 1 A a 2 A b 3 B …
Dance Party2
  • 7,214
  • 17
  • 59
  • 106
99
votes
2 answers

Get records with highest/smallest per group

How can one get records with highest/smallest per group? Former title of this question was "using rank (@Rank := @Rank + 1) in complex query with subqueries - will it work?" because I was looking for solution using ranks, but now I see that the…
Tomas
  • 57,621
  • 49
  • 238
  • 373
40
votes
1 answer

Pandas rank by column value

I have a dataframe that has auction IDs and bid prices. The dataframe is sorted by auction id (ascending) and bid price (descending): Auction_ID Bid_Price 123 9 123 7 123 6 123 2 124 3 124 …
Christopher Jenkins
  • 825
  • 3
  • 12
  • 16
34
votes
1 answer

What does the := operator mean in mysql?

I have a mysql table (scho_id,school_name,school_views). I was looking for a mysql query to get rank of schools on the basis of school_views. I found this solution on stackoverflow. SET @points := -1, @num := 0; SELECT scho_id , school_views ,…
prograshid
  • 876
  • 3
  • 12
  • 32
31
votes
6 answers

How to rank within groups in R?

This is my dataframe: customer_name order_dates order_values 1 John 2010-11-01 15 2 Bob 2008-03-25 12 3 Alex 2009-11-15 5 4 John 2012-08-06 15 5 John …
Saul Feliz
  • 668
  • 3
  • 11
  • 20
29
votes
3 answers

Rank of a matrix in R

I want to test the rank of a matrix, is there someone who can recommend a package/function in R for this?
user1274212
  • 339
  • 1
  • 3
  • 5
26
votes
6 answers

Hive getting top n records in group by query

I have following table in hive user-id, user-name, user-address,clicks,impressions,page-id,page-name I need to find out top 5 users[user-id,user-name,user-address] by clicks for each page [page-id,page-name] I understand that we need to first group…
TopCoder
  • 4,206
  • 19
  • 52
  • 64
24
votes
8 answers

Calculating percentile rank in MySQL

I have a very big table of measurement data in MySQL and I need to compute the percentile rank for each and every one of these values. Oracle appears to have a function called percent_rank but I can't find anything similar for MySQL. Sure I could…
lhahne
  • 5,909
  • 9
  • 33
  • 40
23
votes
6 answers

Pandas rank by multiple columns

I am trying to rank a pandas data frame based on two columns. I can rank it based on one column, but how can to rank it based on two columns? 'SaleCount', then 'TotalRevenue'? import pandas as pd df =…
Anoop
  • 2,748
  • 4
  • 18
  • 27
22
votes
2 answers

SQL Server Query for Rank (RowNumber) and Groupings

I have a table that has some columns: User, Category, Value And I want to make a query that will give me a ranking, of all the users by the value, but reset for the category. Example: user1 CategoryA 10 user2 CategoryA 11 user3 CategoryA…
bladefist
  • 1,084
  • 3
  • 15
  • 25
19
votes
1 answer

pandas group by year, rank by sales column, in a dataframe with duplicate data

I would like to create a rank on year (so in year 2012, Manager B is 1. In 2011, Manager B is 1 again). I struggled with the pandas rank function for awhile and DO NOT want to resort to a for loop. s =…
Ben
  • 381
  • 1
  • 3
  • 15
17
votes
1 answer

Ranking rows using SQL Server Rank function without skipping a rank number

I want to rank rows in a table without skipping numbers in the rank. Please see below example. CREATE TABLE #test( apples int NOT NULL, ) ON [PRIMARY] GO insert into #test( apples ) values ( 10 ) insert into #test( apples ) values ( 10 ) insert…
davomarti
  • 373
  • 2
  • 4
  • 9
16
votes
3 answers

How can I get row's index from a table in SQL Server?

I have a Toplist table and I want to get a user's rank. How can I get the row's index? Unfortunately, I am getting all rows and checking in a for loop the user's ID, which has a significant impact on the performance of my application. How could…
Tugrul Emre Atalay
  • 918
  • 1
  • 9
  • 28
1
2 3
99 100