| SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it. |
|
|||
Calculate the median value of a column?Either directly or using a function (Different database engines might do this differently.)
Definition: The middle value in a distribution, above and below which lie an equal number of values. (Taken from http://www.thefreedictionary.com/median) |
|
|||
|
The following solution is credited to David Rozenshtein, Anatoly Abramovich, and Eugene Birger. More information can be found at http://www.oreilly.com/catalog/transqlcook/chapter/ch08.html.
To calculate the median of the light-bulb test results, use the following query:
SELECT x.Hours median |