https://www.dropbox.com/s/txly3dh2os9oq4x/DBHW03.docx?dl=0 1.Write down the SQL
ID: 3598439 • Letter: H
Question
https://www.dropbox.com/s/txly3dh2os9oq4x/DBHW03.docx?dl=0
1.Write down the SQL to show the average salary for each department together with its department_id. (Hint: 12 records)
2.Write down the SQL to show the department in which the average salary of the employees (whosesalary is greater than 5000) is less than 8000. (hint: 4 records)
3.Write down the SQL to show the full name (in one attribute) of employees and their related department name. If an employee has no department, we will not show this employee record. (hint:106 records)
Explanation / Answer
1.Write down the SQL to show the average salary for each department together with its department_id
Ans:select department_id, avg(salary) from employees group by department_id;
2.Write down the SQL to show the department in which the average salary of the employees (whosesalary is greater than 5000) is less than 8000
Ans:select department_id, avg(salary) from employees where salary>5000 group by department_id having avg(salary)<8000;
3.Write down the SQL to show the full name (in one attribute) of employees and their related department name. If an employee has no department, we will not show this employee record
Ans:select Frst_name || ' ' || last_name as ±ullName, department_name from employees, departments where employees.department_id=departments.department_id;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.