row-number

MS Access alternative to SQL function ROW_NUMBER()

允我心安 提交于 2019-12-10 17:15:15
问题 I work with MS Access 07 and need a little help. I have two tables TbProjectTeam and TbProjectList. I need to compare date of employee turn-out and date of project start. I used that SQL syntax: SELECT [TbProjectTeam ].[Surname, name] FROM TbProjectTeam INNER JOIN TbProjectList ON TbProjectTeam .[DateofTurnOut] <= TbProjectList.[DateOfStart] WHERE TbProjectList.[ID] = 1 ORDER BY [Surname, name]; My aim is to replace 1 in TbSeznamUkolu.[ID] = 1 expression with something as ROW_NUMBER() OVER in

Creating a row number of each row in PySpark DataFrame using row_number() function with Spark version 2.2

只愿长相守 提交于 2019-12-10 09:26:27
问题 I am having a PySpark DataFrame - valuesCol = [('Sweden',31),('Norway',62),('Iceland',13),('Finland',24),('Denmark',52)] df = sqlContext.createDataFrame(valuesCol,['name','id']) +-------+---+ | name| id| +-------+---+ | Sweden| 31| | Norway| 62| |Iceland| 13| |Finland| 24| |Denmark| 52| +-------+---+ I wish to add a row column to this DataFrame, which is the row number (serial number) of the row, like shown below - My final output should be: +-------+---+--------+ | name| id|row_num | +------

Select subset of rows using Row_Number()

浪子不回头ぞ 提交于 2019-12-09 13:33:01
问题 Select id, name, ROW_NUMBER() OVER (ORDER BY id asc) as 'RowNo' from customers where RowNo between 50 AND 60 I am trying to select a subset of rows between 50 and 60 . The problem is 'RowNo' is an invalid column name. Thank you Using SQL SERVER 2008 R2 回答1: Use your query as subquery like bellow: select * from ( Select id, name, ROW_NUMBER() OVER (ORDER BY id asc) as [RowNo] from customers ) t where RowNo between 50 AND 60 You can use CTE as well but whether to choose one over another read

SQL Transpose rows to columns (group by key variable)?

自作多情 提交于 2019-12-09 03:13:43
问题 I am trying to transpose rows into columns, grouping by a unique identifier (CASE_ID). I have a table with this structure: CASE_ID AMOUNT TYPE 100 10 A 100 50 B 100 75 A 200 33 B 200 10 C And I am trying to query it to produce this structure... | CASE_ID | AMOUNT1 | TYPE1 | AMOUNT2 | TYPE2 | AMOUNT3 | TYPE3 | |---------|---------|-------|---------|-------|---------|--------| | 100 | 10 | A | 50 | B | 75 | A | | 200 | 33 | B | 10 | C | (null) | (null) | (assume much larger dataset with large

Rank based on sequence of dates

梦想与她 提交于 2019-12-08 02:58:11
问题 I am having data as below **Heading Date** A 2009-02-01 B 2009-02-03 c 2009-02-05 d 2009-02-06 e 2009-02-08 I need rank as below Heading Date Rank A 2009-02-01 1 B 2009-02-03 2 c 2009-02-05 1 d 2009-02-06 2 e 2009-02-07 3 As I need rank based on date. If the date is continuous the rank should be 1, 2, 3 etc. If there is any break on dates I need to start over with 1, 2, ... Can any one help me on this? 回答1: SELECT heading, thedate ,row_number() OVER (PARTITION BY grp ORDER BY thedate) AS rn

Selecting every Nth row per user in Postgres

此生再无相见时 提交于 2019-12-07 20:17:54
问题 I was using this SQL statement: SELECT "dateId", "userId", "Salary" FROM ( SELECT *, (row_number() OVER (ORDER BY "userId", "dateId"))%2 AS rn FROM user_table ) sa WHERE sa.rn=1 AND "userId" = 789 AND "Salary" > 0; But every time the table gets new rows the result of the query is different. Am I missing something? 回答1: Assuming that ("dateId", "userId") is unique and new rows always have a bigger (later) dateId . After some comments: What I think you need: SELECT "dateId", "userId", "Salary"

LINQ-to-objects index within a group + for different groupings (aka ROW_NUMBER with PARTITION BY equivalent)

好久不见. 提交于 2019-12-07 02:32:38
问题 After much Google searching and code experimentation, I'm stumped on a complex C# LINQ-to-objects problem which in SQL would be easy to solve with a pair of ROW_NUMBER()...PARTITION BY functions and a subquery or two. Here's, in words, what I'm trying to do in code-- the underlying requirement is removing duplicate documents from a list: First, group a list by (Document.Title, Document.SourceId), assuming a (simplified) class definition like this: class Document { string Title; int SourceId;

How to add ROW_NUMBER() in a view?

让人想犯罪 __ 提交于 2019-12-07 01:25:40
问题 In PostgreSQL 8.4 I want to create a view from 3 tables with id. So I want to have this structure in my view: num serial, name_dispatcher character varying(250) the_geom geometry I can select name_dispatcher and the_geom from tables: CREATE VIEW lineView AS SELECT 'name' AS name_dispatcher, the_geom FROM line1 UNION SELECT 'name' AS name_dispatcher, the_geom FROM line2 UNION SELECT 'name' AS name_dispatcher, the_geom FROM line3 How to create the num column in the view? UPDATE I found a

Counting sequential events and counts of sequences SQL

流过昼夜 提交于 2019-12-06 10:50:59
问题 I have a query that I built using an answer found here and it was very helpful. I have added some things to it to suit my needs. One of the things that I added was a ROW_NUMBER() in order to count how many times someone has been readmitted within 30 days over any time length. I have inserted the cte results into a temp table as suggested in the first answer and by a question that was posted here. This does not solve thought, the sequence length and sequence count issue. This is the query: --

How can I delete or select a row from a table that has a specific row number?

断了今生、忘了曾经 提交于 2019-12-06 10:48:48
问题 I have a question about Microsoft SQL Server 2005. How can I delete or select a row from a table that has a specific row number? 回答1: Edit: Modified the code so that it matches more closely to OP's intentions Declare @RowNum as INT SET @RowNum = 15 ---Just for example WITH OrdersRN AS ( SELECT ROW_NUMBER() OVER(ORDER BY OrderDate, OrderID) AS RowNum ,OrderID ,OrderDate ,CustomerID ,EmployeeID FROM dbo.Orders ) SELECT * FROM OrdersRN WHERE RowNum = @RowNum ORDER BY OrderDate ,OrderID; 回答2: