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.