SQL Day2 2
SQL Day2 2
SQL (Day2):
1 Write a query that displays the difference between the highest and lowest salaries.
Label the column DIFFERENCE.
2 From the employees table determine the number of managers without listing them.
Label the column Number of Managers. Hint: Use the MANAGER_ID column to
determine the number of managers.
3 Display the minimum, maximum, sum, and average salary for each job type. Label the
columns Maximum, Minimum, Sum, and Average, respectively. Round the average
salary to the nearest whole number.
4 Display the manager number and the salary of the lowest paid employee for that
manager. Exclude anyone whose manager is not known. Exclude any groups where the
minimum salary is $6,000 or less. Sort the output in descending order of salary.
5 Write a query to display the last name, department number, and department name for
all employees.
7 Display the names and hire dates for all employees who were hired before their
managers, along with their manager's names and hire dates. Label the columns
Employee, Emp Hired, Manager, and Mgr Hired, respectively.
8 Write a query to display each department’s name, location, number of employees, and
the average salary for all employees in that department. Label the columns Name,
Location, Number of People, and Salary, respectively. Round the average salary to two
decimal places.
9 Create a query to display the employee numbers and last names of all employees who
earn more than the average salary. Sort the results in ascending order of salary.
10 Display the minimum salary in each department excluding the (minimum salary in the
company).
11 Create a query to display the employees that earn salary that is higher than the salary
of all the clerks. Sort results on salary from highest to lowest.\ note: use Multi-row sub
query.
select last_name
from employees
where salary > all (select salary from employees
where job_id like '%CLERK')
order by salary desc
12 Bonus:
Display the employee numbers, last names, and salaries of all employees who earn
more than the average salary and who work in a department with any employee with
the letter "u" in their name.
Students Courses
Student_id pk
Student_name not Course_id pk
null Course_name not
Address null
Bdate Credit_hour
Tel Unique
Students_Courses
Course_id
Student_id
Grade(0-100)
Reg_date