DEV Community

Cover image for ✅ SQL Practice Questions with Answers 📊🧠
ssekabira robert sims
ssekabira robert sims

Posted on

✅ SQL Practice Questions with Answers 📊🧠

🔍 Q1. Find the total number of employees in the company.

🗂️ Table: employees(id, name)

Answer:

SELECT COUNT(*) AS total_employees
FROM employees;
Enter fullscreen mode Exit fullscreen mode

🔍 Q2. Calculate the average salary of all employees.

🗂️ Table: employees(name, salary)

Answer:

SELECT AVG(salary) AS average_salary
FROM employees;
Enter fullscreen mode Exit fullscreen mode

🔍 Q3. Get the department-wise total salary expense.

🗂️ Table: employees(name, department, salary)

Answer:

SELECT department, SUM(salary) AS total_salary
FROM employees
GROUP BY department;
Enter fullscreen mode Exit fullscreen mode

🔍 Q4. Find the highest salary in each department.

🗂️ Table: employees(name, department, salary)

Answer:

SELECT department, MAX(salary) AS max_salary
FROM employees
GROUP BY department;
Enter fullscreen mode Exit fullscreen mode

🔍 Q5. Count how many employees earn more than 50,000.

🗂️ Table: employees(name, salary)

Answer:

SELECT COUNT(*) AS high_earners
FROM employees
WHERE salary > 50000;
Enter fullscreen mode Exit fullscreen mode

🔍 Q6. Get the minimum salary in the company.

🗂️ Table: employees(salary)

Answer:

SELECT MIN(salary) AS min_salary
FROM employees;
Enter fullscreen mode Exit fullscreen mode

💬 Tap ❤️ for more!

Top comments (0)