SQL Learning Queries
SQL Learning Queries
alter table ashu add (location varchar2(20) default 'x' not null)
4. Select the name and salary of all employee who are clerks?
7. List the department name and department number for departments with
numbers
greater than or equal to 20?
9. List the names of employees whose salaries are less than 2500?
11. Display the name, monthly salary and daily salary and hourly salary for
employees assume that the sal column in the table is the monthly salary, that there
are 22 working days in a month,and that there are 8 working hours in a day.
rename the columns as monthly,daily,hourly?
12. List the names and employer's numbers of managers who earn more than 2600
display in alphabetic order by name?
Select ename,empno from emp where job='MANAGER' and sal>2600 order by ename;
Select ename from emp where ename like ‘%TH%’ or ename like ‘%LL%’;
15)Select the information about manager and the president from the column job in
the
table emp. Order the result by department number?
16. List the employee name that do not end with "S"?
18. List the name,job and department of everyone whose name falls in the
alphabetic range "C" to "F"?
Select ename from emp where ename like ‘M%’ and ename like ‘%R’;
select ename||' has held the position of '||job||' in department '||deptno||' since '||hiredate
from emp
23. List all rows from emp table ,by comverting the null values in comm column to
0?
24. List all managers and salesman with salaries over 1500?
25. Write a query that will accept a given job title and display all records according
to that title .Accept salary prompt 'enter value for salary'?
29. How many months has the president worked for the company? round th the
nearest
whole number of months?
30. List the names of all employees whose hire date anniversary is in the month of
december?
31. Give sql command to find the average salary per job in each dept .This sql
figures in emp table are for each month?
32. In one query.count the number of people in dept 30 who can receive a salary and
the number of people who receive a commission?
34. Calculate the total compensation expense for each dept. for one year , the sql
comm figures in the emp table are for each month. Assume that employees who do
note earn a commission receive non monetary benefits that are worth $100 a
month?
select deptno,(nvl(sum(comm)*12,0)+sum(nvl(comm,0)+100)*12) "Total"
from emp
group by deptno
/
35. Do a case insensitive search for a list of employees with a job that
a user enters(e.g. clerk)?
37. Which employees earn less than 30% ot the president's salary?
Select ename from emp where sal < 0.3*(select sal from emp where
Job=’PRESIDENT’);
Select MAX(HIREDATE)
from emp
GROUP BY DEPTNO;
39. Create a view consisting of number of employees and their total sum of salary
grouped by deptno?
40. Create a view consisting of number of all the columns from emp table and their
corresponding records from dept. table consisting of dname&location?
*****44. Print a list of employees displaying just salary if more than 1500/if exactly
1500,
display "ON TARGET". if less than 1500 , display "BELOW TARGET"?
SELECT ENAME ONTARGET FROM EMP WHERE SAL>=1500 AND SAL<1500;
45. List the employee names and the cities in whiech they work order by city?
46. Find the number of different employees and the number of departments?
SELECT
COUNT(DISTINCT(EMP.DEPTNO)),SUM(COMM),SUM(SAL),COUNT(DISTINCT(
DEPT.DNAME))
,COUNT(DISTINCT(DEPT.LOC)) FROM EMP,DEPT;
49. Display only those jobs where the minimum salary is greater than or equal to
3000?
Select job,min(sal) from emp having min(sal) >= 3000 group by job
50. Display the average monthly salary bill for each job type within a department?
51. Find out the diffenence between highest and lowest salaries?
55. Display all employee names and their department names in department order?
****58. Find all employees who joined the company before their manager?
60. Find the employees who earn more than the lowest salary in dept 30?
SELECT COUNT(*) FROM EMP
WHERE
DEPTNO=30
AND
SAL >
(SELECT MIN(SAL) FROM EMP WHERE DEPTNO=30)
61. Display employees who has earn more than lowest salary in dept 30?
SELECT ENAME,SAL FROM EMP
WHERE
DEPTNO=30
AND
SAL >
(SELECT MIN(SAL) FROM EMP WHERE DEPTNO=30);
62. Find employees who earn more than every employee in dept 30?
SELECT ENAME,SAL FROM EMP
WHERE
DEPTNO=30
AND
SAL >
any(SELECT distinct(SAL) FROM EMP WHERE DEPTNO=30)
64. Fisplay the name,job,hiredate for employees whose salary is greater than the
highest salary in the sales department?
65. Copy all information on dept10 into the D10 history table?
67. Create in cluster table/cluster index on emp(dept no) and dept(dept no)?
*****
Create cluster emp_clus emp(deptno);
72. List all views which are created for a particular date and table?
73. List all synonym which are created for a particular table and date?
74. List all the objects which are created on a particular date?
75. Display asterisk against the row of the most recently hired employees.display
ename,hiredate & column name showing " * " and column name maxdate (for
unique records)?
76. Delete rows from dept table of those deptnumbers do not have matching rows in
the emp table?
DELETE FROM DEPT
WHERE
DEPTNO
NOT IN
(SELECT EMP.DEPTNO FROM EMP,DEPT
WHERE
DEPT.DEPTNO=EMP.DEPTNO)
79. Display each employee name with hiredate & review date . assume review date is
one year
after hiredate.order output in assending review date order?
80. Write query which will return the day of the week,for any date entered
in the format DD.MM.YY?
82. List the min & max for each job type?
83. Find avg salary & avg total remunation for each job title.remember salesman
earn commision?
85. List the employee name ,job ,salary ,grade,dept name for every one in the
company except clerks.sort on salary displaying the highest salary first?
87. Show name,salary,deptno for any employee who earns a salary greater than the
average for their dept sort in dept order?
88. Who are the top3 carners in the company.display their name and salary?
89. In which year did most people join the company?display the year and number of
employees?
Select to_char(hiredate,’yyyy’),count(ename) from emp
90. Find employees who earn a salary greater than the average salary for their
dept?
91. Find all employees whose dept is not in the dept table ?
92. It has been dicovered that the sales people in dept 30 are not males. produce the
folowing output.
ENAME DEPTNO JOB
______ ________ ____
ALLEN 30 sales person
WARD 30 sales person
BLAKE 30 manager
94. Display the name,job,hiredate ,salary for employees whose salary is greater
than the highest salary in SALES dept?
95. List employees with eaither the same job as jones or a salary greater than or
equal
to ford's order by job and salary?
96. List employees in deptno10 with the same job as anyone in the sales dept?
98:Retrieve the name, department, and salary, of any employee whose salary is
above average for his or her department.
97. List the employees having the same job as employees located in chicago?
99. Set salaries of all salesman equal to 1.1 times the average salary of salesman?
select a.job, round(b.sal*1.1/count('SALESMAN')) sal from
portal30_demo.emp a,portal30_demo.emp b
where a.job = b.job
and a.job = 'SALESMAN'
group by a.job,b.sal
100. Delete all employees with the same job jones.and jones should not be deleted?
102. Write a query to delete the Duplicate rows for Emp table?
DELETE FROM <table_name>
WHERE (ROWID, < column>)
NOT IN
(SELECT MIN(ROWID), <column>
FROM <table_name>
GROUP BY <column>);
103. Write a query to display 5th row to 7th row of Emp Table?
SELECT * FROM
(SELECT ROWNUM <alias>,<column name> FROM
(SELECT <no,column name> FROM <table_name>
ORDER BY <column name>))<alias> --inline function
WHERE A.no > &n and A.no < &m ;
104. Write a query to display the 2nd Max Salary earning employee?
select max(sal) from portal30_demo.emp where sal not in (select max(sal)
sal from portal30_demo.emp)