Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Calculate the Median

Author  Topic 

obiwaugh
Starting Member

27 Posts

Posted - 2004-06-28 : 01:00:16
How does one go about calculating the mean value of a field in a table. For example, I'd like to calculate the median ANNUAL_RT for employees in department 1400.

EMPLID,DEPTID,ANNUAL_RT
100,1400,45000
101,1400,50000
102,1400,70000
103,1400,75000

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-06-28 : 04:31:45
i believe this gives the median value
select sum(ANNUAL_RT) / count(ANNUAL_RT) from Table1

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2004-06-28 : 05:43:11
Do you want the MEAN or the MEDIAN?
If you want the mean then the AVG function should produce equivalent results to SUM/COUNT i.e. SELECT AVG(ANNUAL_RT) FROM Employees WHERE DEPTID = 1400.
If you want the median, there's a very elegant solution from jsmith8858 elsewhere on this forum: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=16257


Mark
Go to Top of Page
   

- Advertisement -