Home > Archive > microsoft.public.sqlserver.server > October 2002 > Median code for SQL Server 7.0





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Median code for SQL Server 7.0
JoanO

2002-10-05, 9:09 pm

If you have code to figure out a median in SQL Server 7.0
could you please send it to me? I know there is an
example in the 7.0 training kit, but I don't have it.

Thanks!
Anith Sen

2002-10-05, 9:09 pm

I am not familiar with the example you are referring to.
You can use the following general methodolgy using TOP to
get the median value. Assuming you have a unique Sequence
or Ranking column, you can try:

SELECT AVG(RankingCol)
FROM (
SELECT MAX(RankingCol)
FROM (
SELECT TOP 50 PERCENT SeqCol
FROM yourTable
ORDER BY SeqCol ASC
) AS _D1(RankingCol)
UNION ALL
SELECT MIN(RankingCol)
FROM (
SELECT TOP 50 PERCENT SeqCol
FROM yourTable
ORDER BY SeqCol DESC
) AS _D2(RankingCol)
) AS _Derived(RankingCol)

--
- Anith





Dejan Sarka

2002-10-05, 9:09 pm

Hi!

You can get Median and more statistical procedures at http://sql.reproms.si.
Go to Code Library - White Papers.

--
Dejan Sarka, SQL Server MVP
FAQ from Neil & others at: http://www.sqlserverfaq.com
Please reply only to the newsgroups.
PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org

"JoanO" <joan.olszewski@eds.com> wrote in message
news:01fc01c25dbf$596fa1a0$35e
f2ecf@TKMSFTNGXA11...
> If you have code to figure out a median in SQL Server 7.0
> could you please send it to me? I know there is an
> example in the 7.0 training kit, but I don't have it.
>
> Thanks!



Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net