Function to Calculate Median in SQL Server

前端 未结 30 2777
孤独总比滥情好
孤独总比滥情好 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:38

    Median Finding

    This is the simplest method to find the median of an attribute.

    Select round(S.salary,4) median from employee S where (select count(salary) from station where salary < S.salary ) = (select count(salary) from station where salary > S.salary)
    

提交回复
热议问题