Vous êtes sur la page 1sur 4

Oracle Assignment 3

Solutions
1.

Find the total sales amount


Ans: select sum(amount) from sales;

2.

Find the customer-wise lowest and highest sales amount


Ans: select custname,max(amount),min(amount) from sales group by custname;

3.

Find product-wise lowest, highest and total sales.


Ans: select prodname,max(amount),min(amount) from sales group by prodname;

4.

Find department-wise average salary for all the departments employing more than three
employees
Ans: select deptno,avg(sal) from emp group by deptno having count(empno)>3;

5.

Find the customer-wise total sales for all the customers except TKB SPORT SHOP who came to
purchase various sports items maximum four times.
Ans:

6.

Display the highest, lowest, sum and average salary for all employees. Label the columns
appropriately.
Ans: select max(sal) MAX_SAL,min(sal) MIN_SAL,sum(sal) SUM_SAL,round(avg(sal))
AVG_SAL from emp;

7.

Modify the above query and display the output for each job type.
Ans: select job,max(sal) MAX_SAL,min(sal) MIN_SAL,sum(sal) SUM_SAL,round(avg(sal))
AVG_SAL from emp group by job;

8.

Write a query to display the number of people with same job.


Ans: select job,count(empno) from emp group by job;

9.

Determine the number of managers without listing them.


Ans: select count(job) as "Manager Count "from emp where job='MANAGER';

10. Write a query that will display the difference between the highest and lowest salaries
Ans: select max(sal)-min(sal) from emp;
11. Display the manager number and salary of the lowest paid employee for that manager.
Ans: select min(sal) from emp group by job having job='MANAGER';

Page 1

Oracle Assignment 3
Solutions
12. Write a query to display the department number, location, number of employees and the average
salary for all employees in that department.
Ans: select e.deptno,d.loc,count(e.empno),avg(e.sal) from dept d,emp e where e.deptno=d.deptno
group by e.deptno,d.loc;
13. Find out the department in which the maximum number of employees works
Ans: select deptno,count(empno) from emp group by deptno having count(empno)=(select
max(count(empno)) from emp group by deptno);
14. Find out department in which no employees are working.
15. List names of people who have salary less than the average salary for dept 20
Ans: select ename,sal from emp where sal<(select avg(sal) from emp where deptno='20' group by
deptno);
16. List number, name, job, manager number and managers job of each employee reporting to them
17. Display information about employees who have the maximum number of employees reporting to
him
18. Display the details of all employees who report to BLAKE
19. List names and hiredates of employees who were hired in the month of December
20. List names and hiredate of employees hired in the year 1980
21. Display names and jobs of the people separated by a hyphen. Capitalize the first character of name
and job.
22. List employee numbers, names and hiredates of the people working in the department number 20,
display the hiredates in the dd/mm/yy format
23. Find number of months the president has worked for the company.
24. Find the day of the week on which SMITH joined
25. Find the time of time of the day in which ADAMS joined
26. Find day of month on which KING joined
27. Find out month on which MARTIN joined
28. Find out which quarter of the year the employees joined. Display their number and names as well
29. Retrieve ANALYST records with the hiredate formatted as The 3rd of December 1984
30. List all names, jobs, and a job classification number, which is to be assigned by you. Translate the
value started in each job field to a job classification number. This is to be done as followsa.

CLERK

b.

MANAGER

c.

PRESIDENT

d.

OTHERS

31. Find the average annual salary per job in each department.
Page 2

Oracle Assignment 3
Solutions
32. Count the number of people in department 30 who receive a salary and the number of people who
receive a commission
33. Compute the average, minimum and maximum salaries of these groups of employees having job
as Clerk or manager, Display the job as well
34. Display the department no of all departments having more than 1 clerks
35. Display the length of the longest employees name
36. Which employees earn less than 30% of the presidents salary?
37. Write an SQL command that displays 2nd highest salary paid
38. Display details of all departments and the corresponding employees
39. Display all customer names with their order details (order number and ship date) for the orders
shipped in 1987.
40. Display salesman names and names of customers they are dealing with.
41. Display salesman who did not earn commission, with customer names whom they are dealing
with.
42. Display salesman names, salary, commission and their salary grades.
43. Display all employee names and the locations of their departments except CHICAGO
44. Display all Tennis products and their price details (standard and minimum price).
45. Display department that has no employees
46. Display the products purchased by either JOCKSPORTS (customer number 100) or JUST
TENNIS (customer number 103) or both of them.
47. Display the products purchased by JOCK SPORTS which are not purchased by JUST TENNIS
48. Write a query to find the employees who earn the lowest salary in each department. Display the
result in the ascending order of salary.
49. Write a query to find out the employees who are first to join their departments
50. Write a query to find the employees who are earning the maximum salary in their departments.
51. Write a query to find the salesman number (repid) who has achieved the maximum total sales
among the entire salesman.
52. Display only the name of the salesman who achieved the maximum total sales among all the
salesman
53. Write a query to display the two lowest earners names and salaries.
54. Create a query to display the name, hiredate, and salary for all employees who have both the same
salary and commission as Scott.
55. Display the department name, and salary of any employee whose salary and commission matches
both the salary and commission of any employee in DALLAS.
56. List all the employees who have at least one person reporting to them.
57. List the employee details if and only if more than 10 employees are present in department no
10.
Page 3

Oracle Assignment 3
Solutions
58. List the name of the employees with their immediate higher authority.
59. List all the employees who do not manage any one.
60. List the employee details whose salary is greater than the lowest salary of an employee belonging
to deptno 20.
61. List the details of the employee earning more than the highest paid manager.
62. List the highest salary paid for each job.
63. Find the most recently hired employee in each department.
64. In which year did most people join the company? Display the year and the number of employees.
65. Which department has the highest annual remuneration bill?
66. Write a query to display a * against the row of the most recently hired employee.
67. Write a correlated sub-query to list out the employees who earn more than the average salary of
their department.
68. Find the 2nd maximum salary.
69. Select the duplicate records (Records, which are inserted, that already exist) in the EMP table.
70. Write a query to list the length of service of the employees (of the form n years and m months).
71. Write a query to display employee name whose name occurs only once in the table.
72. Write a query to display all the details from DEPT table along with the no. of employee working
in each dept.
73. List out the common jobs in Research and Accounting Departments in ascending order.
74. List out the distinct jobs in Sales and Accounting Departments.
75. Which is the department having greater than or equal to 3 employees and display the department
names in ascending order?
76. List out the employees who earn more than every employee in department 30.
77. List out the employees who earn more than the lowest salary in department 30.
78. Find out which department does not have any employees.
79. List out the no. of employees joined in every month in ascending order.
80. How many employees who are joined in 1985.
81. How many employees joined each month in 1985?
82. How many employees who are joined in March 1985.

Page 4

Vous aimerez peut-être aussi