Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Chức năng thứ hạng Khả năng cửa sổ (những VỀ () khoản) tự nó không tạo ra cột ra bất kỳ truy vấn, đó là nơi mà các chức năng xếp hạng đi vào chơi: ROW_NUMBER ■ ■ ■ ■ hạng dense_rank NTILE Chỉ cần được rõ ràng, các chức năng xếp hạng tất cả các yêu cầu các cửa sổ chức năng. Tất cả các chức năng tổng hợp bình thường - SUM (), MIN (), MAX (), COUNT (*), và như vậy - cũng có thể được sử dụng như là chức năng xếp hạng | Part II Manipulating Data With Select 4 43877 5 43894 6 43895 7 43911 1 44109 1 44285 1 44483 2 44501 2001-08-01 00 00 00.000 2001-08-01 00 00 00.000 2001-08-01 00 00 00.000 2001-08-01 00 00 00.000 2001-09-01 00 00 00.000 2001-10-01 00 00 00.000 2001-11-01 00 00 00.000 2001-11-01 00 00 00.000 As expected the windowed sort in this case the RowNumber column restarts with every new month. Ranking Functions The windowing capability the OVER clause by itself doesn t create any query output columns that s where the ranking functions come into play row_number rank dense_rank ntile Just to be explicit the ranking functions all require the windowing function. All the normal aggregate functions SUM MIN MAX COUNT and so on can also be used as ranking functions. Row number function The ROW_NUMBER function generates an on-the-fly auto-incrementing integer according to the sort order of the OVER clause. It s similar to Oracle s RowNum column. The row number function simply numbers the rows in the query result there s absolutely no correlation with any physical address or absolute row number. This is important because in a relational database row position number and order have no meaning. It also means that as rows are added or deleted from the underlying data source the row numbers for the query results will change. In addition if there are sets of rows with the same values in all ordering columns then their order is undefined so their row numbers may change between two executions even if the underlying data does not change. One common practical use of the ROW_NUMBER function is to filter by the row number values for pagination. For example a query that easily produces rows 21-40 would be useful for returning the second page of data for a web page. Just be aware that the rows in the pages may change typically this grabs data from a temp table. It would seem that the natural way to build a row number pagination query would be to simply add the OVER clause and ROW_NUMBER function