row number over
时间: 2023-09-21 07:02:47 浏览: 73
"ROW NUMBER OVER" is a SQL function that allows you to assign a unique sequential number to each row returned in a query result set. It is often used in conjunction with the "ORDER BY" clause to specify the order in which the rows should be numbered. The function syntax is as follows:
```
ROW_NUMBER() OVER (ORDER BY column1 [, column2, ...])
```
For example, the following query returns a result set of employees and assigns a unique sequential number to each row based on their salary in descending order:
```
SELECT ROW_NUMBER() OVER (ORDER BY salary DESC) as row_num, name, salary
FROM employees
```
The result set would look something like this:
```
row_num | name | salary
------- | ------- | ------
1 | Alice | 90000
2 | Bob | 80000
3 | Charlie | 75000
4 | David | 70000
5 | Emily | 65000
```
阅读全文