sqlsunday.com

T-SQL tips and tricks, best practices and query plans from the field.

Skip to content
  • sqlsunday.com
    • About
  • Structured Concepts
    • Master data tool
    • Send passwords
  • Slack app
  • Presentations
  • Downloads
  • Checklists
    • Installing SQL Server 2014
    • Installing SQL Server 2016
    • Installing SQL Server 2017
    • Installing SQL Server 2019
    • Links and utilities
Search

median

Median and percentile in T-SQL

2016-02-11 / Daniel Hutmacher / 1 Comment

Back in 2014 I wrote a blog post on how to calculate a median value using the NTILE window function. It’s far from the best performing solution there is, but it worked on SQL Server 2008, before the introduction of OFFSET-FETCH i SQL Server. In this post, I’m going to look at creating a generalized function that calculates the median (or any percentile) of a series of values.

Continue reading →

Calculating median using the NTILE function

2014-02-162014-02-18 / Daniel Hutmacher / 2 Comments

A while back, I was shown an absolutely gorgeous median calculation, using the new OFFSET/FETCH functionality introduced in SQL Server 2012. But this got me thinking. How can you calculate the median in an older SQL Server? Here’s an idea of how to do it using the NTILE() function.

Continue reading →

Search

Categories

  • By difficulty (194)
    • Advanced (41)
    • Basics (58)
    • Intermediate (97)
  • CLR (1)
  • Code review (1)
  • Off-topic (14)
  • Rant (6)
  • Scripts (19)
  • Series (31)
    • Efficient data (8)
    • Introduction to T-SQL (1)
    • Slowly changing dimensions (5)
    • SQL Server security (17)
  • SQL Server concepts (82)
  • T-SQL (142)
  • Tips (58)
  • Uncategorized (1)
  • Videos (2)
Daniel Hutmacher, Structured Concepts AB

SQL SERVER HELP YOU CAN DEPEND ON.

Need SQL Server help?

At Structured Concepts, we specialize in SQL Server development and performance tuning, as well as technical training for users and developers.

Visit our homepage at strd.co.

Create a website or blog at WordPress.com
  • Follow Following
    • sqlsunday.com
    • Join 1,274 other followers
    • Already have a WordPress.com account? Log in now.
    • sqlsunday.com
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar