Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 12
    This expert analysis makes a compelling argument against the PERCENTILE functions due to poor performance. sqlperformance.com/2012/08/t-sql-queries/median Commented Jan 20, 2015 at 18:38
  • 5
    Don't you need to add a DISTINCT or GROUPY BY SalesOrderID? Otherwise you'll have a lot of duplicate rows.
    – Konstantin
    Commented Feb 23, 2018 at 15:02
  • There is also a discreet version using PERCENTILE_DISC
    – johnDanger
    Commented Nov 20, 2019 at 18:50
  • emphasizing @carl.anderson's point above: a PERCENTILE_CONT solution was measured to be 373x slower (!!!!) compared to the fastest solution they tested on SQL Server 2012 on their particular test schema. Read the article that carl linked for more details. Commented Nov 20, 2019 at 23:00
  • 1
    As of 2022, this performed ~2x faster than the whole select top 50 percent thing. At least in my particular case. So if you're getting perf slowness, check your stats, indexes accordingly. It also reads way clearer imo.
    – JohnnyFun
    Commented Aug 11, 2022 at 17:43