Skip to main content
8 events
when toggle format what by license comment
Aug 11, 2022 at 17:43 comment added JohnnyFun 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.
Feb 18, 2020 at 20:33 comment added user9930055 The top 50% way is' beautiful_clever' but this method works nicely for when there are multiple groupings
Nov 20, 2019 at 23:00 comment added Justin Grant 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.
Nov 20, 2019 at 18:50 comment added johnDanger There is also a discreet version using PERCENTILE_DISC
Feb 23, 2018 at 15:02 comment added Konstantin Don't you need to add a DISTINCT or GROUPY BY SalesOrderID? Otherwise you'll have a lot of duplicate rows.
Jan 20, 2015 at 18:38 comment added carl.anderson This expert analysis makes a compelling argument against the PERCENTILE functions due to poor performance. sqlperformance.com/2012/08/t-sql-queries/median
May 24, 2013 at 22:10 history edited David Fullerton CC BY-SA 3.0
formatting and query simplification
Jan 13, 2012 at 6:15 history answered Simon_Weaver CC BY-SA 3.0