温馨提示×

Oracle rank()与dense_rank()区别

小樊
83
2024-08-06 03:17:12
栏目: 云计算

  1. Oracle RANK():
  • Oracle RANK() function is used to rank rows within a result set, based on a specified column or expression.
  • The RANK() function assigns a unique rank to each row in the result set, where rows with the same value in the specified column or expression are assigned the same rank.
  • If two rows have the same value in the specified column or expression, they will be assigned the same rank, and the next rank will be skipped.
  1. Oracle DENSE_RANK():
  • Oracle DENSE_RANK() function is also used to rank rows within a result set, based on a specified column or expression.
  • The DENSE_RANK() function assigns a unique rank to each row in the result set, where rows with the same value in the specified column or expression are assigned the same rank.
  • Unlike the RANK() function, the DENSE_RANK() function does not skip ranks if two or more rows have the same value in the specified column or expression. It assigns consecutive ranks to all rows.

In summary, the main difference between the RANK() and DENSE_RANK() functions in Oracle is how they handle ties. RANK() may skip ranks if there are ties, while DENSE_RANK() does not skip ranks and assigns consecutive ranks to all rows.

0