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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Average a count - howto?? 1

Status
Not open for further replies.

sparkbyte

Technical User
Sep 20, 2002
879
US
I have tried several ways to do this but cannot seem to figure it out.

Here is the last trial

Code:
select count(distinct BoxNumber) As TtlBoxCount,
	(Select count(*)
		from dbo.tblTrackingTable
		where TrackingDate > '9/20/2010'
		and BoxNumber Like 'NBC%') as TTlFilesBox,
	avg(TTlFilesBox)
	
From dbo.tblTrackingTable
	where TrackingDate > '9/20/2010'
		and BoxNumber Like 'NBC%'


Thanks

John Fuhrman
 
I am not sure about your table structure but you may try something like that.

Code:
with a as (
Select count(*) as TTlFilesBox
from dbo.tblTrackingTable
where TrackingDate > '9/20/2010'
        and BoxNumber Like 'NBC%'
Group By BoxNumber)
select avg(TTlFilesBox), count(*)
from a
 
Thanks, that was just the starter I needed.



Thanks

John Fuhrman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top