You are given an employees table. Write a SQL query to find the average salary for each department.
Return the columns:
Order the results by department name alphabetically.
Return the columns:
department, avg_salaryOrder the results by department name alphabetically.
Available Tables
employees
Table Schemas
CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
department VARCHAR(50) NOT NULL,
salary INT NOT NULL
);
Sample Data
INSERT INTO employees (id, name, department, salary) VALUES (1, 'Alice', 'Engineering', 9500), (2, 'Bob', 'Engineering', 8800), (3, 'Carol', 'Marketing', 6200), (4, 'David', 'Marketing', 5900), (5, 'Eve', 'Engineering', 11200), (6, 'Frank', 'HR', 5400), (7, 'Grace', 'HR', 5100), (8, 'Henry', 'Marketing', 6800);
Log in to see your submissions.
Hints
- Use GROUP BY with AVG(). Don't forget ORDER BY.
Write a query and click Run to see results.

