Implement RowNumber () Over (Partition by) and qlikviewrownumber in SQL Server in QlikView

Source: Internet
Author: User

Implement RowNumber () Over (Partition by) and qlikviewrownumber in SQL Server in QlikView

This is often the case when field A has many duplicate values, but the values in field B are unique After grouping by field A. Therefore, SELECT, when field B is used, you do not know which value in field B is used. Therefore, when field A is repeated, you want to obtain the value of field B, the data must be based on the row corresponding to the maximum and minimum values in field C.

You can use the following method in SQL Server: Row_Number () Over (Partition by A Order by C) ID, and then take ID = 1.

 

QlikView can be implemented as follows:

Data preparation is as follows:

Sales:
LOAD
	Num(SalesManID) as SalesManID,
	Num(ManagerID) as ManagerID,
	Date(Date) as Date
Inline [
SalesManID, ManagerID, Date
21, 190, 2013-05-06
21, 201, 2014-05-06
22, 652, 2013-05-06
23, 813, 2013-05-06
23, 915, 2014-01-06
23, 961, 2014-05-06
];


In the Sales table, the SalesManID is the salesperson ID. in different periods, the SalesManID corresponds to different managerids, and the manager ID of the salesperson should be obtained as needed.

SaleHierarchy:
LOAD
	SalesManID,
	If(Peek("SalesManID")=SalesManID, Peek("RowNumber") + 1, 1) as RowNumber,
	ManagerID,
	Date
Resident
	Sales
Order By
	SalesManID,
	Date desc;

DROP Table Sales;


Note: The Order By SalesManID and Date fields are required.

 


As shown in, getting RowNumber = 1 is the expected result.

Therefore, the code can be written as follows:

SaleHierarchy:
LOAD
	SalesManID,
	If(Peek("SalesManID")=SalesManID, Peek("RowNumber") + 1, 1) as RowNumber,
	ManagerID,
	Date
Resident
	Sales
Where
	If(Peek("SalesManID")=SalesManID, Peek("RowNumber") + 1, 1)=1
Order By
	SalesManID,
	Date desc;

DROP Table Sales;

 


If you do not know how to use Peek, please refer to the help or message.


How does SQL 2000 implement row_number () over (partition by nember order by sl DESC?

Select nember, name, s1, (select count (1) from test where nember = t. nember and s1 <= t. s1)
From test t

Desc is <=, asc is> =
 
Row_number () over (partition by order by) converts SQL 2000

A function can generate sequence numbers.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.