Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is null? median query

Status
Not open for further replies.

lcfc

Programmer
Dec 4, 2001
27
GB
I am using this code to obtain the median from a field:

SELECT Min([Time Arrive to Dr]) FROM [All]
WHERE [Time Arrive to Dr] IN
(SELECT TOP 50 PERCENT [Time Arrive to Dr] FROM [All] ORDER BY [Time Arrive to Dr] DESC)
UNION SELECT Max([Time Arrive to Dr]) FROM [All]
WHERE [Time Arrive to Dr] IN (SELECT TOP 50 PERCENT [Time Arrive to Dr] FROM [All] ORDER BY [Time Arrive to Dr] ASC);

This produces either 1 number or 2, from which i can find the average and thus get the median.

Unfortunatley there are some null cells in the field which i don't want to include in the calculation. How can i filter these out, i.e, where do i put "is not null" in the above code. Thanks
 
SELECT Min([Time Arrive to Dr]) FROM [All]
WHERE [Time Arrive to Dr] IN
(SELECT TOP 50 PERCENT [Time Arrive to Dr] FROM [All] WHERE [Time Arrive to Dr] Is Not Null ORDER BY [Time Arrive to Dr] DESC)
UNION SELECT Max([Time Arrive to Dr]) FROM [All]
WHERE [Time Arrive to Dr] IN (SELECT TOP 50 PERCENT [Time Arrive to Dr] FROM [All] WHERE [Time Arrive to Dr] Is Not Null ORDER BY [Time Arrive to Dr] ASC);


[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top