Hi -
Here's an example, based on Northwind's Orders table, that will return count,
min, max, mean. As you know, Access has no Median function so you have to
roll your own. Function Medianf(), shown below will do that for you.
SELECT
Count(Orders.Freight) AS CountOfFreight
, Min(Orders.Freight) AS MinOfFreight
, Max(Orders.Freight) AS MaxOfFreight
, Avg(Orders.Freight) AS MeanOfFreight
, Medianf("Orders","Freight") AS MedianOfFreight
FROM
Orders;
Function MedianF(pTable As String, pfield As String) As Single
'*******************************************
'Purpose: Return median value from a recordset
'Coded by: raskew
'Inputs: ? medianF("Orders", "Freight") <enter.
'Output: 41.36 (may vary according to how much
' you've fiddled with this table).
'*******************************************
Dim rs As Recordset
Dim strSQL As String
Dim n As Integer
Dim sglHold As Single
strSQL = "SELECT " & pfield & " from " & pTable & " WHERE " & pfield &
">0 Order by " & pfield & ";"
Set rs = CurrentDb.OpenRecordset(strSQL)
rs.MoveLast
n = rs.RecordCount
rs.Move -Int(n / 2)
If n Mod 2 = 1 Then 'odd number of elements
MedianF = rs(pfield)
Else 'even number of elements
sglHold = rs(pfield)
rs.MoveNext
sglHold = sglHold + rs(pfield)
MedianF = sglHold / 2
End If
rs.Close
End Function
is it also possible to count the number of
instances where the same value has occured ..eg in the above example- 10.2
has occured twice haemoglobin field is a number..
Short answer: No! That's going to have to be a separate query.
HTH - Bob