sqlbeginner10 minutes
Fix the SQL Query to Correctly Calculate Average Salary
This challenge requires you to debug a simple SQL query that attempts to calculate the average salary from an employees table, but the query contains syntax errors that prevent it from running correctly.
Challenge prompt
You are given a broken SQL query that is supposed to return the average salary from the employees table. The query currently throws a syntax error. Identify and fix the errors so that the query runs successfully and returns the correct average salary.
Guidance
- • Check the function name spelling and syntax used for calculating averages.
- • Ensure all necessary keywords like SELECT and FROM are included correctly.
- • Verify that the table and column names are referenced correctly and consistently.
Hints
- • The SQL aggregate function to calculate average is spelled 'AVG', not 'average'.
- • Every SELECT query must specify columns after SELECT and a source table after FROM.
- • Pay attention to commas and parentheses placement in your query.
Starter code
SELECT average(salary FROM employees;Expected output
A single numeric value representing the average salary from the employees table.
Core concepts
SQL syntax basicsAggregate functionsBasic SELECT queries
Challenge a Friend
Send this duel to someone else and see if they can solve it.