SQL Server Developer Edition 2014
I have a table that looks like:
+ ID + CC + Xa +
| 1 | 0 | 53.1 |
| 1 | 1 | 46.1 |
| 1 | 2 | 107.5|
| 2 | 0 | 36.5 |
| 2 | 1 | 41.5 |
| 2 | 2 | 61.8 |
Xa
are floats in the table, but I rounded to make it less messy. I had heard of PERCENTILE_DISC from MSDN, and made a query that I thought would give me the median of Xa
for each ID
:
SELECT DISTINCT s.ExperimentID,
PERCENTILE_DISC(.5) WITHIN GROUP( ORDER BY s.Xa) OVER (PARTITION BY s.ExperimentID)
FROM Simulations s
I threw in the DISTINCT ExperimentID because when I ran the query without it, it was looking to return the median of all ~150M rows for each individual row, which doesn't really make any sense. I did get results, and I think they're right, but I'm not certain. I compared the results of some individual IDs vs what I got from MEDIAN() in LibreOffice, and the results are slightly different. Any idea why?