Function to Calculate Median in SQL Server

前端 未结 30 2823
孤独总比滥情好
孤独总比滥情好 2020-11-22 04:03

According to MSDN, Median is not available as an aggregate function in Transact-SQL. However, I would like to find out whether it is possible to create this functionality (u

30条回答
  •  鱼传尺愫
    2020-11-22 04:20

    For large scale datasets, you can try this GIST:

    https://gist.github.com/chrisknoll/1b38761ce8c5016ec5b2

    It works by aggregating the distinct values you would find in your set (such as ages, or year of birth, etc.), and uses SQL window functions to locate any percentile position you specify in the query.

提交回复
热议问题