ranking

Why null values are not ranking same in mysql?

£可爱£侵袭症+ 提交于 2019-12-13 03:35:55
问题 Yesterday I asked a question about ranking students by their points. [Rank users in mysql by their points ] I actually solved my problem with the help I've recieved from other question (thanks to everyone who helped me). Meanwhile I figured out something accidently. If I try to rank my students by their points and if points column was empty (NULL) my query didn't gave an error also it sorted ranks like 1-2-3-4 but all values were NULL this is the query I've tried select er.*, (@rank := if(

PostgreSQL: getting ordinal rank (row index? ) efficiently

拟墨画扇 提交于 2019-12-12 21:06:43
问题 You have a table like so: id dollars dollars_rank points points_rank 1 20 1 35 1 2 18 2 30 3 3 10 3 33 2 I want a query that updates the table's rank columns ( dollars_rank and points_rank ) to set the rank for the given ID, which is just the row's index for that ID sorted by the relevant column in a descending order. How best to do this in PostgreSQL? 回答1: @OMG_Ponies already pointed it out: The window function dense_rank() is what you need - or maybe rank() . The UPDATE could look like this

Complex “featured product” model using query-time ranking (optional filters)

夙愿已清 提交于 2019-12-12 19:53:22
问题 I have a products index that displays filtered results on category pages. For a given category , any amount of products may be flagged as featured , meaning it displays first. When products are displayed for a category , only one featured product should show at a time (at random from the available products flagged as featured) Additionally, a product should not be flagged as featured if it has date range fields and the current date is not within the range So, my index might look something

MySQL - select rank for users in a score table

拟墨画扇 提交于 2019-12-12 15:31:27
问题 I've got a 'user_score' table with that structure: |id|user_id|group_id|score| timestamp | | 1| 1| 1| 500| 2013-02-24 18:00:00| | 2| 2| 1| 200| 2013-02-24 18:01:50| | 3| 1| 2| 100| 2013-02-24 18:06:00| | 4| 1| 1| 6000| 2013-02-24 18:07:30| What I need to do is to select all users from that table which are from the exact group. Select their actual (according to timestamp) score in that group and their rank. What I have is ( edit: after Jocachin's comment I found out that my own query does not

r element frequency and column name

放肆的年华 提交于 2019-12-12 04:56:05
问题 I have a dataframe that has four columns A, B, C and D: A B C D a a b c b c x e c d y a d z e f I would like to get the frequency of all elements and lists of columns they appear, ordered by the frequency ranking. The output would be something like this: Ranking frequency column a 1 3 A, B, D c 1 3 A, B, D b 2 2 A, C d 2 2 A, B e 2 2 A, D f ..... I would appreciate any help. Thank you! 回答1: Something like this maybe: Data df <- read.table(header=T, text='A B C D a a b c b c x e c d y a d NA

Specific group rankings in R

ぐ巨炮叔叔 提交于 2019-12-12 04:06:41
问题 I have the data frame "Category", "ID", "Score(t)", and I want to get "Rank(t)": Category ID Score.08.2007 Score.09.2007 Rank.08.2007 Rank.09.2007 ... Orange FSGBR070N3 0.16 ... 5 ... Orange FSGBR070N3 0.05 ... 7 ... Orange FSGBR070N3 0.11 6 Orange FS00008L4G 0.28 1 Orange FS00008VLD 0.27 2 Orange FS00008VLD 0.27 2 Orange FS00008VLD 0.27 2 Orange FS00009SQX -2.03 8 Orange FS00009SQX NA Orange FSUSA0A1KW NA Orange FSUSA0A1KW NA Orange FSUSA0A1KX NA Orange FSUSA0A1KY NA Orange FS0000B389 NA

PHP MYSQL query result “RANKING”

ぐ巨炮叔叔 提交于 2019-12-12 01:35:35
问题 I need to get a list of users Ranking by points and from my command line (MySQL) is was able to generate the necessary code: SET @rank=0; SELECT rank, iduser, pontos FROM ( SELECT @rank:=@rank+1 AS rank, SUM(points.points) AS pontos, points.iduser, users.name, users.idade FROM points INNER JOIN users ON (points.iduser = users.id) WHERE (users.idade >= %s) AND (users.idade <= %s) GROUP BY points.iduser ORDER BY pontos DESC) AS totals WHERE iduser = %s The problem is that I need this to run on

How to make your ranking values show integer (without decimals) in R data.table

北城以北 提交于 2019-12-11 18:24:15
问题 I have to rank a data set ordered by several variables in this data set and grouped by another variable of it. When I use ranking methods on a data.table, the ranking values are decimals. I'd need them to be integer numbers without decimal part. Bellow, I´m providing a summary of what I need. I´m copying somebody else's example from another question in this website (and also related to ranking methods). I found the answer to that question useful, but it still doesn't provide the way to make

Using LIMIT within GROUP BY to get N results per group?

南笙酒味 提交于 2019-12-11 16:57:11
问题 The following query: SELECT year, id, rate FROM h WHERE year BETWEEN 2000 AND 2009 AND id IN (SELECT rid FROM table2) GROUP BY id, year ORDER BY id, rate DESC yields: year id rate 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001 p01 5.9 2007 p01 5.3 2009 p01 4.4 2002 p01 3.9 2004 p01 3.5 2005 p01 2.1 2000 p01 0.8 2001 p02 12.5 2004 p02 12.4 2002 p02 12.2 2003 p02 10.3 2000 p02 8.7 2006 p02 4.6 2007 p02 3.3 What I'd like is only the top 5 results for each id: 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001

Next permutation/ranking with specific strength

大兔子大兔子 提交于 2019-12-11 15:50:37
问题 I am searching an algorithm which gives me the next permutation with a specific strength. A permutation of length n is defined with the elements (1,2,3,...n) What is the strength of a permutation? The strength of a permutation with length 10 is definded as |a1-a2|+|a2-a3|+...+|a9-a10|+|a10-a1| . For example: (1,2,3,4,5,6) has the strength 10 (1,2,6,3,4,5) has the strength 14 Exist there a formula to compute the next permutation of a given strength and length, or its necesary to compute all