RANK() vs DENSE_RANK() in SQL: What’s the Difference?

Many RDBMSs include both a rank() and a dense_rank() function in their list of window function offerings. At first glance, these functions might appear to do the same thing. However, there’s one important difference between these functions, and you will definitely need to be aware of this difference when choosing which function to use.

Continue reading

An Introduction to the MEDIAN() Function in SQL

Some relational database management systems (RDBMSs) have a MEDIAN() function that calculates the median value within a range of values.

It returns the middle value or an interpolated value that would be the middle value once the values are sorted.

The SQL MEDIAN() function typically operates on numeric expressions, but depending on the RDBMS, may also operate on other data types, such as datetime expressions.

Depending on the RDBMS, the MEDIAN() function can be used as a window function, as an aggregate function, or as both.

Continue reading