sql production number of ways of recording the query

row_number ()   the Order ()  function for each row of the query is generated out of a record number, in order to sort and will not be repeated, attention must be used over clause to select a column to sort in order to use row_number function to generate numbers.

Rank ()   Order ()  function is used to rank the partition return a result set for each row, the ranking is the number of rows before the relevant row rank plus one. Simply rank function is to check out the record ranking with row_number function is different, taking into account the rank function clause over the same sort field value, if the rank function used to generate a number, for the same field in OVER ordering the same, under a different sort of field is an order of a + on the same field order.

DENSE_RANK () Order ()  function is similar to the rank function, considering the same over the sort field value clause case, except that DENSE_RANK () generated number is continuous, when there is the same rank, the same as in a field value when the ranking followed by a ranking value, i.e. a ranking value plus 1, for example, for DENSE_RANK (), there are two first sort, then the next is a second sort, and for rank () for two The first sort is the third under a sort. Results In the case DENSE_RANK () and Rank () does not exist in the same field and ROW_NUMBER () is the same.

There are the following data:

ROW_NUMBER   the Order () Order number ascending Sort :

Rank ()  the Order () Order number ascending Sort :

dense_rank() order()按订单号由小到大排序

Guess you like

Origin www.cnblogs.com/sugarwxx/p/9829039.html