dense-rank

Oracle SQL - DENSE_RANK

我与影子孤独终老i 提交于 2019-12-30 22:57:54
问题 I have a Client data table, selected columns of which are shown below: Row_ID Client_ID Status_ID From_date To_date 1 123456 4 20/12/2007 18:02 20/12/2007 18:07 2 789087 4 20/12/2007 18:02 20/12/2007 18:07 3 789087 4 20/12/2007 18:07 20/12/2007 18:50 4 789087 4 20/12/2007 18:50 21/12/2007 10:38 5 123456 4 20/12/2007 18:07 20/12/2007 18:50 6 123456 4 20/12/2007 18:50 21/12/2007 10:38 7 123456 4 21/12/2007 10:38 21/12/2007 16:39 8 789087 4 21/12/2007 10:38 21/12/2007 17:54 9 789087 4 21/12/2007

How to get the rank of a specific user in a particular subject for all the subjects scored acknowledging ties

我只是一个虾纸丫 提交于 2019-12-29 09:45:30
问题 --------------------------------------------------------------------- id | stid | Subject | Total_cumulative | Year | ---------------------------------------------------------------------- 1 | 23 | English | 40 | 2014/2015 2 | 1 | English | 29 | 2014/2015 3 | 13 | Maths | 40 | 2014/2015 4 | 4 | Physics | 60 | 2014/2015 5 | 13 | Commerce | 40 | 2014/2015 6 | 1 | Biology | 89 | 2014/2015 7 | 13 | English | 29 | 2014/2015 8 | 13 | Agric | 60 | 2014/2015 Now I have a query that gets all of a

select with window function (dense_rank()) in SparkSQL

我们两清 提交于 2019-12-24 19:09:03
问题 I have a table which contains records for customer purchases, I need to specify that purchase was made in specific datetime window one window is 8 days , so if I had purchase today and one in 5 days its mean my purchase if window number 1, but if I did it on day one today and next in 8 days, first purchase will be in window 1 and the last purchase in window 2 create temporary table transactions (client_id int, transaction_ts datetime, store_id int) insert into transactions values (1,'2018-06

Islands and Gaps Issue

安稳与你 提交于 2019-12-22 08:44:43
问题 Backstory: I have a database that has data points of drivers in trucks which also contain the. While in a truck, the driver can have a 'driverstatus'. What I'd like to do is group these statuses by driver, truck. As of now, I've tried using LAG/LEAD to help. The reason for this is so I can tell when a driverstatus change occurs, and then I can mark that row as having the last datetime of that status. That in itself is insufficient, because I need to group the statuses by their status and date

Join single row from a table in MySQL

本秂侑毒 提交于 2019-12-22 08:27:08
问题 I have two tables players and scores . I want to generate a report that looks something like this: player first score points foo 2010-05-20 19 bar 2010-04-15 29 baz 2010-02-04 13 Right now, my query looks something like this: select p.name player, min(s.date) first_score, s.points points from players p join scores s on s.player_id = p.id group by p.name, s.points I need the s.points that is associated with the row that min(s.date) returns. Is that happening with this query? That is, how can I

Exclude null values using DENSE_RANK

你离开我真会死。 提交于 2019-12-22 07:05:54
问题 Dense_Rank is taking everything into account. Is there a way to exclude the null values so the next rank after 1 would be 2 and not 3. This is what the table looks like now: A | DENSE_R -------------- 1 | 1 -------------- 2 | null -------------- 3 | 3 -------------- 4 | 4 This is what I want the table to look like: A | DENSE_R -------------- 1 | 1 -------------- 2 | null -------------- 3 | 2 -------------- 4 | 3 I'm using the following code to do so:- WITH CTE AS ( SELECT A FROM A1 ) SELECT A

DENSE_RANK() without duplication

痞子三分冷 提交于 2019-12-19 08:03:13
问题 Here's what my data looks like: | col1 | col2 | denserank | whatiwant | |------|------|-----------|-----------| | 1 | 1 | 1 | 1 | | 2 | 1 | 1 | 1 | | 3 | 2 | 2 | 2 | | 4 | 2 | 2 | 2 | | 5 | 1 | 1 | 3 | | 6 | 2 | 2 | 4 | | 7 | 2 | 2 | 4 | | 8 | 3 | 3 | 5 | Here's the query I have so far: SELECT col1, col2, DENSE_RANK() OVER (ORDER BY COL2) AS [denserank] FROM [table1] ORDER BY [col1] asc What I'd like to achieve is for my denserank column to increment every time there is a change in the value

how to find the pathing flow and rank them using pig or hive?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 03:25:36
问题 Below is the example for my use case. 回答1: You can reference this question where an OP was asking something similar. If I am understanding your problem correctly, you want to remove duplicates from the path, but only when they occur next to each other. So 1 -> 1 -> 2 -> 1 would become 1 -> 2 -> 1 . If this is correct, then you can't just group and distinct (as I'm sure you have noticed) because it will remove all duplicates. An easy solution is to write a UDF to remove those duplicates while

Group By records based on 10 second time interval in SQL server

血红的双手。 提交于 2019-12-12 03:24:28
问题 Requirement is to Group record of table based on 10 second time interval. Given table Id DateTime Rank 1 2011-09-27 18:36:15 1 2 2011-09-27 18:36:15 1 3 2011-09-27 18:36:19 1 4 2011-09-27 18:36:23 1 5 2011-09-27 18:36:26 1 6 2011-09-27 18:36:30 1 7 2011-09-27 18:36:32 1 8 2011-09-27 18:36:14 2 9 2011-09-27 18:36:16 2 10 2011-09-27 18:36:35 2 Group Should be like this Id DateTime Rank GroupRank 1 2011-09-27 18:36:15 1 1 2 2011-09-27 18:36:15 1 1 3 2011-09-27 18:36:19 1 1 4 2011-09-27 18:36:23

Dense_rank first Oracle to Postgresql convert

泪湿孤枕 提交于 2019-12-11 17:03:08
问题 I'm trying to convert the following Oracle query into Postgresql. I could convert the rest of the blocks, the problem is I don't know how to convert this block: SELECT ai.uid ,max(ai.OWNER) KEEP ( dense_rank first ORDER BY ai.AGENT_ID DESC ) AS OWNER ,max(ai.EMPLOYEE_KEY) KEEP ( dense_rank first ORDER BY ai.AGENT_ID DESC ) AS EMPLOYEE_KEY ,max(ai.MANAGER_LOGIN) KEEP ( dense_rank first ORDER BY ai.AGENT_ID DESC ) AS MANAGER ,max(ai.CALL_CENTER_NAME) KEEP ( dense_rank first ORDER BY ai.AGENT_ID