Link to home
Start Free TrialLog in
Avatar of Brickwall
BrickwallFlag for United States of America

asked on

Average query based on difference

I have data in a table like this

Date  |   Serial Number  |   Reading
5-1-2012| 12345|12345
5-2-2012|12345|12348


So i figured out how to get the diference between the 2 values as  3 for 5-2.

  and i can run this now for all on one serial number but now i want average how much it changes with all 250 items.  So i have 250 unique seril nubers.  and the readings are all different numbers,  but the differences are relatively close.  I want to average the change between values.  ANy one know how to do this?
Avatar of Habib Pourfard
Habib Pourfard
Flag of New Zealand image

This gives you average of reading for each serial number:
SELECT [Serial Number]
	 , avg(Reading)
FROM YourTable
GROUP BY [Serial Number]

Open in new window


this query gives you max difference of the smalles reading and biggest reading for each serial number:

SELECT [Serial Number]
	 , Max(Reading) - Min(Reading)
FROM YourTable
GROUP BY [Serial Number]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of deighton
deighton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial