75 SQL Questions & Answers
75 SQL Questions & Answers
75 SQL Questions & Answers
1.Display employees who joined in 2000 and doing job that has maximum salary more than 10000.
and
select job_id,min_salary,employee_id,salary
-- no data found
from employees
group by department_id,hire_date
7.Display job id, department id and sum of salary by including all possible dimensions.
select job_id,department_id,sum(salary)
from employees
group by cube(department_id,job_id)
order by department_id,job_id
8.Display employee name and job title of jobs where salary of employee is between minimum and
maximum salary for job.
10.Display first name, job title, department name of employees who joined on 28th Feb.
11.Display details of jobs where the minimum salary is greater than 10000.
12.Display the first name and join date of the employees who joined between 2002 and 2005.
13.Display first name and join date of the employees who is either IT Programmer or Sales Man.
16.Display first name, salary, commission pct, and hire date for employees with salary less than 10000.
17.Display job Title, the difference between minimum and maximum salaries for jobs with max salary in
the range 10000 to 20000.
20.Display employees where the first name or last name starts with S.
21.Display employees who joined in the month of May.
22.Display details of the employees where commission percentage is null and salary in the range 5000 to
10000 and department is 30.
23Display first name and date of first salary of the employees.
26.Display first name and last name after converting the first letter of each name to upper case and the
rest to lower case.
from employees
29.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.
31.Display the number of days between system date and 1st January 2011.
32.Display how many employees joined in each month of the current year.
34.Display employee ID and the date on which he ended his previous job.
where to_char(hire_date,'dd')>15;
group by country_id;
37.Display average salary of employees in each department who have commission percentage.
from employees
group by department_id;
38.Display job ID, number of employees, sum of salary, and difference between highest salary and
lowest salary of the employees of the job.
select
from
employees
group by
job_id;
39.Display job ID for jobs with average salary more than 10000.
from employees
group by job_id
41.Display departments in which more than five employees have commission percentage.
select department_id
from employees
group by department_id
42.Display employee ID for employees who did more than one job in the past.
select employee_id
from job_history
group by employee_id
from employees
group by department_id,to_char(hire_date,'yyyy')
order by department_id
from employees
group by department_id,manager_id
45.Change salary of employee 115 to 8000 if the existing salary is less than 6000.
update employees_table
46.Change job ID of employee 110 to IT_PROG if the employee belongs to department 10 and the
existing job ID does not start with IT.
update employees_table
and
department_id = 10
and
group by department_name;
48.Display job title, employee ID, number of days between ending date and starting date for all jobs in
department 30 from job history.
and
jh.department_id = 30
(or)
where department_id = 30
and
j.job_id = jh.job_id
and
e.job_id = j.job_id
and
group by job_title
53.Display job title, employee name, and the difference between maximum salary for the job and salary
of the employee.
select last_name,job_title
and
department_id = 30
55.Display details of jobs that were done by any employee who is currently drawing more than 15000 of
salary.
select j.*,salary,first_name
and
and round(months_between(end_date,start_date)/12)<6
and
d.location_id = l.location_id
60.Display department name, average salary and number of employees with commission within the
department.
group by department_name
61.Display the month in which more than 5 employees joined in any department located in Sydney.
and
d.location_id = l.location_id
group by to_char(hire_date,'month')
or
SELECT TO_CHAR(HIRE_DATE,'MON-YY')
62.Display details of departments in which the maximum salary is more than 10000.
select department_name,max(salary)
group by department_name
select j.*,first_name
66.Display job title and average salary for employees who did a job in the past.
select job_title,avg(salary),
where employee_id in
group by job_title
--67.Display country name, city, and number of departments where department has more than 5
employees. (wrong)
select c.country_name,l.city,d.department_id,count(employee_id)
group by country_name,city,employee_id
having e.employee_id>5
group by m.employee_id,m.first_name
71.Display the details of departments in which the max salary is greater than 10000 for employees who
did a job in the past.
where employee_id in
group by department_id,employee_id
where employee_id in
73.Display the details of employees drawing the highest salary in the department.
select * from
from employees e
)
where rank = 1;
select e.employee_id,l.city
and
d.location_id = l.location_id
and
e.employee_id = 105
75.Display third highest salary of all employees
select * from
where rank = 3;