SQL QuestSQL Interview Questions › Aggregation & Grouping

Average Salary by Department

EasyFreeQuerying BasicsAggregation & Grouping

Comp planning wants a single-line summary per department: department name and average salary (rounded to the nearest dollar so the spreadsheet doesn't show 12 decimals).

Show department and ROUND(AVG(salary), 0) AS avg_salary. Group by department. Order by avg_salary descending.

The pattern is GROUP BY → one aggregate per metric → ROUND for presentation. AVG() ignores NULLs by default, so missing salaries don't poison the mean (though they do shrink the denominator).

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

employees

emp_idnamedepartmentpositionsalaryhire_datemanager_idperformance_rating
1Alice JohnsonEngineeringSenior Developer950002019-03-1554.5
2Bob SmithEngineeringDeveloper750002020-06-0113.8
3Carol WilliamsMarketingMarketing Manager850002018-09-20NULL4.2

Expected output: Engineering | 85000, Marketing | 60000

Hint

The hint for this one spells out most of the query, so it stays in the editor. Reach for SELECT, GROUP BY, AVG, and open the hint there if you stall.

Concepts

SELECT GROUP BY AVG ROUND Aggregation

Practise the topic: SQL practice questions · GROUP BY exercises

In these company practice sets

Plaid · Goldman Sachs

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Counting RowsEasy · FreeSUM, AVG, MIN, MAXEasy · FreeGROUP BY BasicsEasy · FreeMonthly Order CountEasy · FreeHow Many Genres Do We Cover? (DISTINCT)Easy · FreeFemale Survivor CountEasy · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test