How to Emulate the MEDIAN() Aggregate Function Using Inverse Distribution Functions

Some databases are awesome enough to implement the MEDIAN() aggregate function. Remember that the MEDIAN() is sligthly different from (and often more useful than) the MEAN() or AVG() (average). While the average is calculated as the SUM(exp) / COUNT(exp), the MEDIAN() tells you that 50% of all values in the sample are higher than the … Continue reading How to Emulate the MEDIAN() Aggregate Function Using Inverse Distribution Functions

CUME_DIST(), a Lesser-Known SQL Gem

When doing reporting or statistics with SQL, you better know your window functions. There are many of them, and few SQL developers know about them. CUME_DIST() is one such function. We've recently re-discovered it on Stack Overflow. The following query yields two times the same result for fraction1 and fraction2: SELECT ename, CUME_DIST() OVER (ORDER … Continue reading CUME_DIST(), a Lesser-Known SQL Gem