Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Trying to Find a Simple Average

Author  Topic 

jpiscit1
Posting Yak Master

130 Posts

Posted - 2003-04-03 : 23:03:22
Hi,

Im trying to find an average for a given set of records.

I have a table that accumulates production at 1 min intervals. Each record stores the product name and campaign number. As a result I can run a query as such and get a list of the losses for each run where the campaign number is distinctively listed in he table.

DECLARE @Product char (10)
SET @Product = 'ProductName'

SELECT Distinct campaign_number,
SUM (couch_speed/3 *(DateDiff (ss,(CONVERT(datetime, Loop_pump_start)),(CONVERT(datetime, Turn_up_button_pressed)))/60)-113.72)
FROM tbl_3PMStartTimes
WHERE tbl_3PMStartTimes.product = @Product
GROUP BY campaign_number

I end up with a result such as:

Campaign Losses
301498 213.013329
301513 314.113322
301534 339.880000
301561 188.279992

I'm trying to get the average losses in this result. In this case it would be 263.82. Any suggestions on how I can do this? Any help is appreciated.

John


samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-04-04 : 00:23:25
HTH..

SELECT AVG(A.losses) as AVG_Losses from
(
SELECT Distinct campaign_number,
SUM (couch_speed/3 *(DateDiff (ss,(CONVERT(datetime, Loop_pump_start)),(CONVERT(datetime, Turn_up_button_pressed)))/60)-113.72) as losses
FROM tbl_3PMStartTimes
WHERE tbl_3PMStartTimes.product = @Product
GROUP BY campaign_number
) as A

Sekar
~~~~
Success is not a destination that you ever reach. Success is the quality of your journey.
Go to Top of Page
   

- Advertisement -