Avatar of Murray Brown
Murray Brown
Flag for United Kingdom of Great Britain and Northern Ireland asked on

SQL Removing an average from SQL

Hi. I am trying to take the average out of this SQL statement but get various errors. How would the statement look without the averaging? Thanks


SELECT Categories.[Sub Category] As Result, Round(avg((CAST([Score] as Float) / 5 * 100)), 2) AS Score FROM Answers LEFT JOIN Categories ON Answers.Category = Categories.ID GROUP BY Categories.[Main Category], Categories.[Sub Category], Answers.Survey, Answers.ReviewerID, Answers.CompanyID HAVING (((Categories.[Main Category])='INTERPERSONAL') AND ((Answers.Survey)='1') AND ((Answers.ReviewerID)='R') AND ((Answers.CompanyID)='XYZ')) Order By Result
Microsoft SQL Server 2008

Avatar of undefined
Last Comment
Murray Brown

8/22/2022 - Mon
AdamCz

hello

Please post the error or output and what contain Score field.

Regards
a
Murray Brown

ASKER
Hi. Slight adjustment. If I change the following SQL Statement to the one below that I get the following error
The following error occured while executing the query:
Server: Msg 189, Level 15, State 1, Line 1
The round function requires 2 to 3 arguments.
Incorrect syntax near 'Categories'


SELECT Categories.[Sub Category] As Result, Round(avg((CAST([Score] as Float) / 5 * 100)), 2) AS Score, Questions.Question FROM (Answers LEFT JOIN Categories ON Answers.Category = Categories.ID) LEFT JOIN Questions ON Answers.Category = Questions.Category GROUP BY Categories.[Main Category], Categories.[Sub Category], Answers.Survey, Answers.ReviewerID, Questions.Question, Answers.CompanyID HAVING (((Categories.[Main Category])='INTERPERSONAL') AND ((Answers.Survey)='1') AND ((Answers.ReviewerID)='R') AND ((Answers.CompanyID)='XYZ')) Order By Result

SELECT Categories.[Sub Category] As Result, Round([Score]/ 5 * 100), 2) AS Score, Questions.Question FROM (Answers LEFT JOIN Categories ON Answers.Category = Categories.ID) LEFT JOIN Questions ON Answers.Category = Questions.Category GROUP BY Categories.[Main Category], Categories.[Sub Category], Answers.Survey, Answers.ReviewerID, Questions.Question, Answers.CompanyID HAVING (((Categories.[Main Category])='INTERPERSONAL') AND ((Answers.Survey)='1') AND ((Answers.ReviewerID)='R') AND ((Answers.CompanyID)='XYZ')) Order By Result
ASKER CERTIFIED SOLUTION
AdamCz

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Murray Brown

ASKER
Thanks
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes