ranking

PHP MYSQL group ranking query

倾然丶 夕夏残阳落幕 提交于 2019-11-28 12:18:31
问题 CREATE TABLE `players` ( `pid` int(2) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `team` varchar(20) NOT NULL, `age` int(2) NOT NULL, PRIMARY KEY (`pid`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `players` (`pid`, `name`, `age`, `team`) VALUES (1, 'Samual', 25, 'aa'), (2, 'Vino', 20, 'bb'), (3, 'John', 20, 'dd'), (4, 'Andy', 22, 'cc'), (5, 'Brian', 21, 'dd'), (6, 'Dew', 24, 'xx'), (7, 'Kris', 25, 'qq'), (8, 'William', 26, 'cc'), (9, 'George', 23

Power BI: TopN and All Other

我的梦境 提交于 2019-11-28 10:14:50
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... The end result should look like this (n=3 in this example): Type Amount Orange 169 Apple 158 Banana

Calculate rank with ties based on more than one variable

落爺英雄遲暮 提交于 2019-11-28 09:33:15
问题 I'm trying to compute a medal table for a sports event. My data looks like this: test <- data.frame("ID" = c("1_1", "1_2", "1_3", "1_4","1_5","1_6"), "gold"=c(10, 4, 1, 7, 7, 1), "silver"=c(1, 3, 2, 19, 19, 2), "bronze"=c(1, 8, 2, 0, 0, 2)) First, I want to order the data based on number of "gold", "silver", and "bronze", like this: (test_ordered <- with(test, test[order(-gold, -silver, -bronze), ])) Then compute the final medal rank. This is how the final rank column should like: (test

How do I preserve continuous (1,2,3,…n) ranking notation when ranking in R?

孤街醉人 提交于 2019-11-28 05:41:34
问题 If I want to rank a set of numbers using the minimum rank for shared cases (aka ties): dat <- c(13,13,14,15,15,15,15,15,15,16,17,22,45,46,112) rank(dat, ties = 'min') I get the results: 1 1 3 4 4 4 4 4 4 10 11 12 13 14 15 However, I want the rank to be a continuous series consisting of 1,2,3,... n , where n is the number of unique ranks . Is there a way to make rank (or a similar function) rank a series of numbers by assigning ties to the lowest rank as above but instead of skipping

MySQL update statement to store ranking positions

本小妞迷上赌 提交于 2019-11-28 05:33:38
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 that in reality that could be a few thousand - that could take forever! Does anyone have an idea on a

Draw histograms per row over multiple columns in R

跟風遠走 提交于 2019-11-28 01:22:53
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 22.3 16.2 11 OC 28.6 44.0 24.9 27.9 34.0 30.7 Then I rank colleges using this commend HEIrank1<-(STOF[,

Wikidata results sorted by something similar to a PageRank

主宰稳场 提交于 2019-11-27 23:51:10
In Wikidata ( Wikidata SPARQL endpoint ), is there a way to order the SPARQL query results with something like a PageRank? SELECT DISTINCT ?entity ?entityLabel WHERE { ?entity wdt:P31 wd:Q5. SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } } LIMIT 100 OFFSET 0 Can we specify a field to order the results by and that field expresses that the entity at the top is more notable/important/recognizable that the following one and so on? It seems that PageRank does not make much sense in relation to Wikidata. Obviously, large classes and large aggregates will be leaders. Also, unlike

Find largest and second largest element in a range

风流意气都作罢 提交于 2019-11-27 22:27:55
问题 How do I find the above without removing the largest element and searching again? Is there a more efficient way to do this? It does not matter if the these elements are duplicates. 回答1: for (e: all elements) { if (e > largest) { second = largest; largest = e; } else if (e > second) { second = e; } } You could either initialize largest and second to an appropriate lower bound, or to the first two items in the list (check which one is bigger, and don't forget to check if the list has at least

C# Ranking of objects, multiple criteria

旧街凉风 提交于 2019-11-27 20:17:16
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], [TotalScore] Now, I only have List, Dictionary, and etc. to work with Specifically: Dictionary

Hot content algorithm / score with time decay

我是研究僧i 提交于 2019-11-27 19:44:29
问题 I have been reading + researching on algorithms and formulas to work out a score for my user submitted content to display currently hot / trending items higher up the list, however i'll admit i'm a little over my head here. I'll give some background on what i'm after... users upload audio to my site, audios have several actions: Played Downloaded Liked Favorited Ideally i want an algorithm where I can update an audios score each time a new activity is logged (played, download etc...), also a