ranking-functions

Reset Row Number on value change, but with repeat values in partition

和自甴很熟 提交于 2021-02-10 10:54:23
问题 I'm having trouble with something very similar to this question T-sql Reset Row number on Field Change The solution to this question is perfect, works fine. Except when I try with multiple other 'custno', it breaks down. What I mean by that: custno moddate who -------------------------------------------------- 581827 2012-11-08 08:38:00.000 EMSZC14 581827 2012-11-08 08:41:10.000 EMSZC14 581827 2012-11-08 08:53:46.000 EMSZC14 581827 2012-11-08 08:57:04.000 EMSZC14 581827 2012-11-08 08:58:35

Windowing function in Hive

霸气de小男生 提交于 2020-03-17 18:55:42
问题 I am exploring windowing functions in Hive and I am able to understand the functionalities of all the UDFs. Although, I am not able to understand the partition by and order by that we use with the other functions. Following is the structure that is very similar to the query which I am planning to build. SELECT a, RANK() OVER(partition by b order by c) as d from xyz; Just trying to understand the background process involved for both keywords. Appreciate the help :) 回答1: RANK() analytic

How can I group student scores into quintile using SQL Server 2008

混江龙づ霸主 提交于 2020-01-11 14:29:30
问题 Can anyone help me to group student scores into quintile? I think there is a feature in SQL Server 2012, but still we haven t upgraded to it as we are using 2008R2. I tried Ntile(5)` but it is not generating the desired result. I need below Quintile column Student Score Quintile ------------------------ Student1 20 1 Student2 20 1 Student3 30 2 Student4 30 2 Student5 40 2 Student6 40 2 Student7 50 3 Student8 50 3 Student9 60 3 Student10 70 4 Student11 70 4 Student12 80 4 Student13 80 4

Calculating SQL Server ROW_NUMBER() OVER() for a derived table

天大地大妈咪最大 提交于 2019-12-17 19:39:23
问题 In some other databases (e.g. DB2, or Oracle with ROWNUM ), I can omit the ORDER BY clause in a ranking function's OVER() clause. For instance: ROW_NUMBER() OVER() This is particularly useful when used with ordered derived tables, such as: SELECT t.*, ROW_NUMBER() OVER() FROM ( SELECT ... ORDER BY ) t How can this be emulated in SQL Server? I've found people using this trick, but that's wrong, as it will behave non-deterministically with respect to the order from the derived table: -- This

Assigning rank to a variable based on 2 other variables in stata

半世苍凉 提交于 2019-12-14 04:22:37
问题 I have a longitudinal data with some variables as: firm id , event date , abnormal return , where event date is acquisition announcement date by each firm and abnormal return is the event-announcement return for each firm over a window of 5 days (-2,+2). Here each sample firm engages in multiple acquisitions over a pre-defined period. For e.g., I have 200 firms, each having multiple abnormal return-observations for the period 1999-2011. Therefore, each firm has at least 2 such observations

Ranking algorithm with missing values and bias

对着背影说爱祢 提交于 2019-12-13 05:00:12
问题 The problem is : A set of 5 independent users where asked to rate 50 products given to them. All 50 products would have been used by the users in some point of time. Some users have more bias towards certain products. One user did not truly complete the survey and gave random values. It is not necessary for the users to rate all the products. Now given a 4 sample dataset , rank the products based on ratings datset : product #user1 #user2 #user3 #user4 #user5 0 29 - 10 90 12 1 - - - - 7 2 - -

How can I group student scores into quintile using SQL Server 2008

雨燕双飞 提交于 2019-12-02 14:11:32
Can anyone help me to group student scores into quintile? I think there is a feature in SQL Server 2012, but still we haven t upgraded to it as we are using 2008R2. I tried Ntile(5)` but it is not generating the desired result. I need below Quintile column Student Score Quintile ------------------------ Student1 20 1 Student2 20 1 Student3 30 2 Student4 30 2 Student5 40 2 Student6 40 2 Student7 50 3 Student8 50 3 Student9 60 3 Student10 70 4 Student11 70 4 Student12 80 4 Student13 80 4 Student14 90 5 You must have been doing something wrong when using NTILE(5) - that IS the function to use!

Update a MySQL table with record rankings within groups

人走茶凉 提交于 2019-12-02 06:28:09
问题 I have a table called 'winners' with columns 'id', 'category', 'score', 'rank'. I need to update my table and asign a rank within the subcategories (category_id) which as per the sample is 2 but could be more than that in the future. Most anwers I've found are based around select statements which simply tends to just output the table view but I did find a very good 'Update' answer (https://stackoverflow.com/a/2727239/4560380) specifically the answer update where ties are required to share the

Update a MySQL table with record rankings within groups

为君一笑 提交于 2019-12-02 00:21:16
I have a table called 'winners' with columns 'id', 'category', 'score', 'rank'. I need to update my table and asign a rank within the subcategories (category_id) which as per the sample is 2 but could be more than that in the future. Most anwers I've found are based around select statements which simply tends to just output the table view but I did find a very good 'Update' answer ( https://stackoverflow.com/a/2727239/4560380 ) specifically the answer update where ties are required to share the same rank. Sample CREATE TABLE winners ( id int, category_id int, score double, rank int ); INSERT

Calculating SQL Server ROW_NUMBER() OVER() for a derived table

倖福魔咒の 提交于 2019-11-28 11:00:52
In some other databases (e.g. DB2, or Oracle with ROWNUM ), I can omit the ORDER BY clause in a ranking function's OVER() clause. For instance: ROW_NUMBER() OVER() This is particularly useful when used with ordered derived tables, such as: SELECT t.*, ROW_NUMBER() OVER() FROM ( SELECT ... ORDER BY ) t How can this be emulated in SQL Server? I've found people using this trick , but that's wrong, as it will behave non-deterministically with respect to the order from the derived table: -- This order here ---------------------vvvvvvvv SELECT t.*, ROW_NUMBER() OVER(ORDER BY (SELECT 1)) FROM (