Dac DBT SQL Exercises and Solutions Assignments III IV V
Dac DBT SQL Exercises and Solutions Assignments III IV V
Queries
1. Display details of jobs where the minimum salary is greater than 10000.
2. Display the first name and join date of the employees who joined between 2002
and 2005.
6. Display first name, salary, commission pct, and hire date for employees with
salary less than 10000.
7. Display job Title, the difference between minimum and maximum salaries for
jobs with max salary in the range 10000 to 20000.
10. Display employees where the first name or last name starts with S.
12. Display details of the employees where commission percentage is null and salary
in the range 5000 to 10000 and department is 30.
16. Display first name and last name after converting the first letter of each name to
upper case and the rest to lower case.
18. Display the length of first name for employees where last name contain character
‘b’ after 3rd position.
19. Display first name in upper case and email address in lower case for employees
where the first name and email address are same irrespective of the case.
21. Display the number of days between system date and 1st January 2011.
22. Display how many employees joined in each month of the current year.
24. Display employee ID and the date on which he ended his previous job.
26. Display the country ID and number of cities we have in the country.
27. Display average salary of employees in each department who have commission
percentage.
28. Display job ID, number of employees, sum of salary, and difference between
highest salary and lowest salary of the employees of the job.
29. Display job ID for jobs with average salary more than 10000.
31. Display departments in which more than five employees have commission
percentage.
32. Display employee ID for employees who did more than one job in the past.
33. Display job ID of jobs that were done by more than 3 employees for more than
100 days.
35. Display departments where any manager is managing more than 5 employees.
36. Change salary of employee 115 to 8000 if the existing salary is less than 6000.
37. Insert a new employee into employees with all the required details.
40. Insert a row into departments table with manager ID 120 and location ID in any
location ID for city Tokyo.
42. Display job title, employee ID, number of days between ending date and starting
date for all jobs in department 30 from job history.
46. Display job title, department name, employee last name, starting date for all jobs
from 2000 to 2005.
49. Display last name, job title of employees who have commission percentage and
belongs to department 30.
50. Display details of jobs that were done by any employee who is currently drawing
more than 15000 of salary.
SELECT JH.*
FROM JOB_HISTORY JH JOIN EMPLOYEES E ON (JH.EMPLOYEE_ID =
E.EMPLOYEE_ID)
WHERE SALARY > 15000;
51. Display department name, manager name, and salary of the manager for all
managers whose experience is more than 5 years.
52. Display employee name if the employee joined before his manager.
53. Display employee name, job title for the jobs employee did in the past where the
job was done less than six months.
56. Display the month in which more than 5 employees joined in any department
located in Sydney.
SELECT TO_CHAR(HIRE_DATE,'MON-YY')
FROM EMPLOYEES JOIN DEPARTMENTS USING (DEPARTMENT_ID) JOIN
LOCATIONS USING (LOCATION_ID)
WHERE CITY = 'Seattle'
GROUP BY TO_CHAR(HIRE_DATE,'MON-YY')
HAVING COUNT(*) > 5;
57. Display details of departments in which the maximum salary is more than 10000.
59. Display jobs into which employees joined in the current year.
60. Display employees who did not do any job in the past.
61. Display job title and average salary for employees who did a job in the past.
62. Display country name, city, and number of departments where department has
more than 5 employees.
SELECT COUNTRY_NAME, CITY, COUNT(DEPARTMENT_ID)
FROM COUNTRIES JOIN LOCATIONS USING (COUNTRY_ID) JOIN DEPARTMENTS
USING (LOCATION_ID)
WHERE DEPARTMENT_ID IN
(SELECT DEPARTMENT_ID FROM EMPLOYEES
GROUP BY DEPARTMENT_ID
HAVING COUNT(DEPARTMENT_ID)>5)
GROUP BY COUNTRY_NAME, CITY;
64. Display employee name, job title, start date, and end date of past jobs of all
employees with commission percentage null.
65. Display the departments into which no employee joined in last two years.
66. Display the details of departments in which the max salary is greater than 10000
for employees who did a job in the past.
67. Display details of current job for employees who worked as IT Programmers in
the past.
select salary
from employees main
where 2 = (select count( distinct salary )
from employees
where salary > main.salary);