Assignment Four
Name: Sewbesew Yimer
Instruction: write the right query for following questions.
1. Total Salary by Department
o Write a query to calculate the total salary paid to employees in each department.
2. Average Salary by Job
o Write a query to find the average salary for each job title.
3. Employee Count by Department
o Write a query to count the number of employees in each department.
4. Maximum Salary by Department
o Write a query to find the maximum salary in each department.
5. Minimum Salary by Department
o Write a query to find the minimum salary in each department.
6. Average Salary Across All Employees
o Write a query to calculate the average salary of all employees.
7. Total Salary Paid
o Write a query to calculate the total salary paid to all employees.
8. Count of Employees with Commission
o Write a query to count the number of employees who receive a commission.
9. Count of Employees by Job Title
o Write a query to count the number of employees in each job id.
10. Total Salary by Manager
o Write a query to calculate the total salary of employees under each manager.
Solutions:
1. Total Salary by Department
SELECT department_id,
SUM(salary) AS total_salary
FROM employees
GROUP BY department_id;
2. Average Salary by Job
SELECT job_title,
AVG(salary) AS average_salary
FROM employees
GROUP BY job_title;
3. Employee Count by Department
SELECT department_id,
COUNT(*) AS employee_count
FROM employees
GROUP BY department_id;
4. Maximum Salary by Department
SELECT department_id,
MAX(salary) AS maximum_salary
FROM employees
GROUP BY department_id;
5. Minimum Salary by Department
SELECT department_id,
MIN(salary) AS minimum_salary
FROM employees
GROUP BY department_id;
6. Average Salary Across All Employees
SELECT AVG(salary) AS average_salary
FROM employees;
7. Total Salary Paid
SELECT SUM(salary) AS total_salary
FROM employees;
8. Count of Employees with Commission
SELECT COUNT(*) AS employees_with_commission
FROM employees
WHERE commission IS NOT NULL;
9. Count of Employees by Job Title
SELECT job_id,
COUNT(*) AS employee_count
FROM employees
GROUP BY job_id;
10. Total Salary by Manager
SELECT manager_id,
SUM(salary) AS total_salary
FROM employees
GROUP BY manager_id;