Click here to Skip to main content
15,886,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to calculate the average but i keep on getting this error :

Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

SQL
select fa.new_contractid,AVG(Sum(vews.TransactionCount)) as BillableUsage from BingMapsPlatform_Staging.dbo.VEWSDailyAggTrans vews
inner join BingMapsPlatform_MSCRM.dbo.FilteredAccount fa
on fa.new_accountid=vews.PrimaryId
where fa.new_contractid = '6145412166'
group by fa.new_contractid


How should i modify the script to get the average.
Posted

Try this

SQL
select fa.new_contractid,AVG(Sum(vews.TransactionCount)) as BillableUsage from BingMapsPlatform_Staging.dbo.VEWSDailyAggTrans vews,BingMapsPlatform_MSCRM.dbo.FilteredAccount fa
where fa.new_accountid=vews.PrimaryId
and fa.new_contractid = '6145412166'
group by fa.new_contractid
 
Share this answer
 
Hi Prasant,

try this

SQL
select fa.new_contractid,AVG(Summation) as BillableUsage from(select Sum(vews.TransactionCount) as Summation from BingMapsPlatform_Staging.dbo.VEWSDailyAggTrans) vews
inner join BingMapsPlatform_MSCRM.dbo.FilteredAccount fa
on fa.new_accountid = vews.PrimaryId
where fa.new_contractid = '6145412166'
group by fa.new_contractid

SQL



Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900