ranking

selecting top N rows for each group in a table

旧巷老猫 提交于 2019-11-27 04:00:59
I am facing a very common issue regarding "Selecting top N rows for each group in a table". Consider a table with id, name, hair_colour, score columns. I want a resultset such that, for each hair colour, get me top 3 scorer names. To solve this i got exactly what i need on Rick Osborne's blogpost "sql-getting-top-n-rows-for-a-grouped-query" That solution doesn't work as expected when my scores are equal. In above example the result as follow. id name hair score ranknum --------------------------------- 12 Kit Blonde 10 1 9 Becca Blonde 9 2 8 Katie Blonde 8 3 3 Sarah Brunette 10 1 4 Deborah

Power BI: TopN and All Other

梦想与她 提交于 2019-11-27 03:32:00
问题 I have a data set that resembles the following: Year Location Type Amount 2015 West Apple 12 2015 West Pear 14 2015 East Apple 55 2015 South Orange 62 2015 West Orange 64 2015 East Banana 12 2015 North Banana 23 2015 East Peach 43 2015 East Apple 89 2015 West Banana 77 2015 West Orange 43 2015 North Apple 2 And I need it to be summarized to show TopN as well as all other in order to keep the grand total the same. Just filtering to show only the TopN reduces the grand total and will not work..

How do I find the closest values in a Pandas series to an input number?

只谈情不闲聊 提交于 2019-11-27 01:02:18
I have seen: how do I find the closest value to a given number in an array? How do I find the closest array element to an arbitrary (non-member) number? . These relate to vanilla python and not pandas. If I have the series: ix num 0 1 1 6 2 4 3 5 4 2 And I input 3, how can I (efficiently) find? The index of 3 if it is found in the series The index of the value below and above 3 if it is not found in the series. Ie. With the above series {1,6,4,5,2}, and input 3, I should get values (4,2) with indexes (2,4). You could use argsort() like Say, input = 3 In [198]: input = 3 In [199]: df.ix[(df[

MySQL update statement to store ranking positions

妖精的绣舞 提交于 2019-11-26 22:46:40
问题 I'm trying to get my head around a query and I just can't figure it out. I would appreciate if someone give me a pointer. As a simple example of what I'm trying to achieve, I have these records in the database Score|Ranking ------------- 100 |0 200 |0 300 |0 And I would like the Ranking field to contain 1,2,3 based on who's got the highest score so the result should be: Score|Ranking ------------- 100 |3 200 |2 300 |1 At the moment, I'm doing a for next loop for all these records but given

Draw histograms per row over multiple columns in R

拈花ヽ惹草 提交于 2019-11-26 21:54:55
问题 I'm using R for the analysis of my master thesis I have the following data frame: STOF: Student to staff ratio HEI.ID X2007 X2008 X2009 X2010 X2011 X2012 1 OP 41.8 147.6 90.3 82.9 106.8 63.0 2 MO 20.0 20.8 21.1 20.9 12.6 20.6 3 SD 21.2 32.3 25.7 23.9 25.0 40.1 4 UN 51.8 39.8 19.9 20.9 21.6 22.5 5 WS 18.0 19.9 15.3 13.6 15.7 15.2 6 BF 11.5 36.9 20.0 23.2 18.2 23.8 7 ME 34.2 30.3 28.4 30.1 31.5 25.6 8 IM 7.7 18.1 20.5 14.6 17.2 17.1 9 OM 11.4 11.2 12.2 11.1 13.4 19.2 10 DC 14.3 28.7 20.1 17.0

sort in matlab and assign ranking

别说谁变了你拦得住时间么 提交于 2019-11-26 21:41:23
问题 Hi I need to sort a vector and assign a ranking for the corresponding sorting order. I'm using sort function [sortedValue_X , X_Ranked] = sort(X,'descend'); but the problem is it assigns different ranks for the same values (zeros). i.e. x = [ 13 15 5 5 0 0 0 1 0 3] and I want zeros to take the same last rank which is 6 and fives needs to share the 3rd rank etc.. any suggestions? 回答1: The syntax [sortedValues, sortedIndexes] = sort(x, 'descend') does not return rank as you describe it. It

C# Ranking of objects, multiple criteria

爱⌒轻易说出口 提交于 2019-11-26 20:15:57
问题 I am building a plugin for a LAN party website that I wrote that would allow the use of a Round Robin tournament. All is going well, but I have some questions about the most efficient way to rank over two criteria. Basically, I would like the following ranking layout: Rank Wins TotalScore PersonE 1 5 50 PersonD 2 3.5 37 PersonA 2 3.5 37 PersonC 4 2.5 26 PersonB 5 2.5 24 PersonF 6 0 12 In SQL server, I would use: SELECT [Person], RANK() OVER (ORDER BY Wins DESC, TotalScore DESC) [Rank], [Wins]

Implementing the Hacker News ranking algorithm in SQL

≡放荡痞女 提交于 2019-11-26 19:15:50
问题 Here's how Paul Graham describes the ranking algorithm for Hacker News: News.YC's is just (p - 1) / (t + 2)^1.5 where p = points and t = age in hours I'd like to do that in pure mySQL given the following tables: Table Posts with fields postID (index) and postTime (timestamp). Table Votes with fields voteID (index), postID, and vote (integer, 0 or 1). The idea of the vote field is that votes can be rescinded. For the purposes of the ranking, vote=0 is equivalent to no vote at all. (All votes

Row Rank in a MySQL View

放肆的年华 提交于 2019-11-26 16:45:33
问题 I need to create a view that automatically adds virtual row number in the result. the graph here is totally random all that I want to achieve is the last column to be created dynamically. > +--------+------------+-----+ > | id | variety | num | > +--------+------------+-----+ > | 234 | fuji | 1 | > | 4356 | gala | 2 | > | 343245 | limbertwig | 3 | > | 224 | bing | 4 | > | 4545 | chelan | 5 | > | 3455 | navel | 6 | > | 4534345| valencia | 7 | > | 3451 | bartlett | 8 | > | 3452 | bradford | 9 |

Comparison-based ranking algorithm

萝らか妹 提交于 2019-11-26 15:21:06
问题 I would like to rank or sort a collection of items (with size potentially greater than 100,000) where items in the collection have no intrinsic (comparable) value, instead all I have is the comparisons between any two items which have been provided by users in a subjective manner. Example: Consider a collection with elements [a, b, c, d] and comparisons by users b > a , a > d , d > c . The correct order of this collection would be [b, a, d, c] . This example is simple, however there could be