[Database] basic usage of the ROW_NUMBER () OVER function, row_numberover
(1) ROW_NUMBER () OVER (order by column)
Generally, developers and administrators use temporary table and column-related subqueries in a query to calculate and generate row numbers. SQL Server 2005 now provides a function to generate row numbers instead of all redundant code.
To put it simply, row_number () starts from 1 and returns a number for each group record. ROW_NUMBER () OVER (order by xlh DESC) first orders the CourseID column in descending ORDER, return a sequence number for all xlh records after descending order.
Select ROW_NUMBER () over (order by CourseID desc) as RowIndex, * from TeacherRoles where ClassCode = '20140901'
Usage of over () and row_number () functions in SQL
Select row_number () over (order by xxxx) from xxxx;
It is found that the sequence sorted by xxxx starts from 1.
How to Use the row_number () over Function
In short, row_number () starts from 1 and returns a number for each group record. ROW_NUMBER () OVER (order by xlh DESC) first orders the xlh column in descending ORDER, return a sequence number for no xlh records after descending order. You spell the SQL statement in the program, so it is a "string" + "string.
Example:
Xlh row_num
1700 1
1500 2
1085 3
710 4
680 5
If you still don't understand it, ask me again.