row_number() over (partition by nf order by cs desc)
时间: 2023-10-27 12:49:27 浏览: 39
This SQL expression uses the window function "row_number()" to assign a unique row number to each row within a partition defined by the "nf" column. The rows within each partition are further ordered by the "cs" column in descending order.
For example, if we have a table with columns "nf" and "cs" and the following data:
nf | cs
---|---
A | 10
A | 20
B | 15
B | 5
The expression "row_number() over (partition by nf order by cs desc)" would produce the following result:
nf | cs | row_number
---|---|-----------
A | 20 | 1
A | 10 | 2
B | 15 | 1
B | 5 | 2
Note that within each partition (A and B), the rows are ordered by descending "cs" values and assigned a row number accordingly. The row number starts from 1 for each partition.