Essa é uma consulta em SQL para calcular a mediana.
A tabela "minhaTabela" com o campo 'valores':
SELECT(
(SELECT MAX(valores) FROM (SELECT TOP 50 PERCENT valores FROM minhaTabela ORDER BY valores ) AS BottomHalf)
+ (SELECT MIN(valores) FROM (SELECT TOP 50 PERCENT valores FROM minhaTabela ORDER BY valores DESC) AS TopHalf )
) / 2 AS Median
FROM minhaTabela
O código em ASP no dreamweaver fica assim:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim Recordset1
Dim Recordset1_cmd
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_conn_minhaConexao_STRING
Recordset1_cmd.CommandText ="SELECT( (SELECT MAX(sales) FROM (SELECT TOP 50 PERCENT sales FROM Total_Sales ORDER BY sales) AS BottomHalf) + (SELECT MIN(sales) FROM (SELECT TOP 50 PERCENT sales FROM Total_Sales ORDER BY sales DESC) AS TopHalf)) / 2 AS Median FROM Total_Sales"
Recordset1_cmd.Prepared = true
Set Recordset1 = Recordset1_cmd.Execute
medianaNum =CStr(Recordset1.Fields.Item("Median").Value)
Response.Write ("medianaNum="+medianaNum)
Recordset1.Close()
Set Recordset1 = Nothing
%>