đŸ§Ē Practice SQL: Salary & Department Counts

đŸ§Ē SQL Practice: Salary Summaries & Department Counts

Try the following SQL queries using this sample employee data. Practice grouping by departments, counting employees, and calculating salary aggregates.

📋 Sample employees Table:

employee_id name department_id salary
1Arif10150000
2Nasrin10152000
3Rafi10247000
4Ritu10360000
5Faruk10151000

📝 Practice Queries:

1️⃣ Total Salary Paid Per Department

Goal: Find the total salary for each department.

SELECT department_id, SUM(salary) AS total_salary
FROM employees
GROUP BY department_id;

Expected Output:

department_id total_salary
101153000
10247000
10360000

2️⃣ Employee Count Per Department

Goal: Count the number of employees in each department.

SELECT department_id, COUNT(*) AS employee_count
FROM employees
GROUP BY department_id;

Expected Output:

department_id employee_count
1013
1021
1031

3️⃣ Average Salary of Departments with More Than 1 Employee

Goal: Show average salary for departments with more than 1 employee.

SELECT department_id, AVG(salary) AS avg_salary
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 1;

Expected Output:

department_id avg_salary
10151000
📌 Tips:
  • Use SUM(), AVG(), COUNT() for aggregation.
  • GROUP BY groups rows by column.
  • HAVING filters grouped results (like WHERE, but after grouping).
SQL practice salary, group by query, department-wise employee count, SQL practice for beginners, SQL Bangladesh tutorial, MySQL salary summary, group by having example, SQL query output table

āĻ•োāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāχ:

āĻāĻ•āϟি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āϟ āĻ•āϰুāύ