
Amedeo F. answered 12/14/20
SQL Server and Data Analytics Developer with 20 years experience
Hello,
Using the information (field names and tables) provided in your question, I recommend writing a two queries.
First query returns the average score for all states:
SELECT AVG(avg_math_4_score) AS avg_math_4_score
FROM naep
WHERE year = '2000'
The second query returns states that are less than the average score using the first query as a nested Select:
SELECT state AS below_average_states_y2000, AVG(avg_math_4_score)AS state_avg_math_4_score
FROM naep
WHERE year = '2000'
GROUP BY state
HAVING AVG(avg_math_4_score) < (SELECT AVG(avg_math_4_score) AS avg_math_4_score
FROM naep
WHERE year = '2000')