ccmret (4/1/2013)
Is there any easier way to do this sum/divide without having to put results of sum in a temp table first? Trying to do it all in one query give me:Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
SELECT Distinct LEFT(CONVERT(DateTime, IndexDate , 110), 11)AS IndexDate,
COUNT(*) AS No_Records,
Round(AVG(Test1),2) As Test1_AVG,
Round(AVG(Test2),2) AS Test2_AVG,
SUM(t_complete/COUNT (*)) As Percent_Complete
FROM TestScores.dbo.Analysis
Group by IndexDate
You can't do it like that because you have an aggregate within an aggregate.
Try this.
SUM(t_complete)/COUNT (*) As Percent_Complete
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/