Sie sind auf Seite 1von 11

Employee

Ename City
Anil Nagpur
Shankar Bombay
Jaya Madras
Sunil Bombay
Vijay Delhi
Prakash Calcutta
Ajay madras

Emp_company
Ename Ename Salary Jdate
Anil Acc 1500.00 01-may-89
Shankar Tata 2000.00 10-jul-90
Jaya Cmc 1800.00 07-jun-91
Sunil Cmc 1700.00 01-jan-88
Vijay Tata 5000.00 03-jan-88
Prakash Tata 3000.00 27-may-89
Ajay Acc 8000.00 30-apr-95
Amol Acc 1000.00 17-may-95

Company
Cname City
Acc Madras
Tata Bombay
Acc Nagpur
Cmc Bombay
Cmc Madras
Tata delhi

Manager
Ename Mname
Anil Ajay
Shankar Vijay
Jaya -
Sunil Jaya
Vijay -
Prakash Shankar
Ajay -

Emp_shift
Ename Shift
Anil A
Sunil B
Vijay B
Prakash C

1. using describe command


2. get the data from emp_company
3. getting information only ename,cname,salary,jdate
4. getting information only cname, city
5. retrieving the name of the company located in the city ‘BOMBAY’
Alias :
1.
Set Operator :
1. getting the cities of companies ACC and TATA
2.

1. Create tables according to the following definition.


Deposit
Actno Cname Bname Amount Adate
100 Anil Vrec 1000 01—mar-95
101 Sunil Ajni 5000 4-jan-96
102 Mehul Karolbagh 3500 17-Nov-95
104 Madhuri chandni 1200 17-dec-95
105 Pramod m.g.road 3000 27-mar-96
106 Sandip Andheri 2000 31-mar-96
107 Shivani Virar 1000 5-sep-95
108 Kranti Nehruplace 5000 02-jul-95
109 Naren Powai 7000 10-aug-95

Branch
Bname City
Vrce Nagpur
Ajni Nagpur
Karolbagu Delhi
Chandni Delhi
Dharampeth Nagpur
m.g.road Banglore
Andheri Bombay
Virar Bombay
Nehru place Delhi
Powai Bombay

Cutomer
Cname City
Anil Calcutta
Sunil Delhi
Mehul Baroda
Mandar Patna
Madhuri Nagpur
Pramod Nagpur
Sandip Surat
Shivani Bombay
Krinti Bombay
Naren bombay

Borrow
Loanno Cname Bname Amount
201 Anil Vrce 1000
206 Mehul Ajni 5000
311 Sunil Dharampeth 3000
321 Madhuri Andheri 2000
375 Pramod Virar 8000
481 Kranti Nehru place 3000

Selecting data from single table :

1. list all data from table deposit


2. list all data from table barrow
3. list all data from table customer
4. list all data from branch
5. give account number and amount of depositors
6. give cname and account number of depositors
7. give name of customers
8. give names of branches
9. give names of barrowers
10. give names of customers living in city nagpur
11. give names of depositors having amount greater than 4000
12. give account date of customer anil
13. give names of all branches located in city Bombay
14. give name of borrower having load no 206
15. give name of depositors having account at vrce
16. give name of all branches located in city delhi
17. give names of customers who opened account after date ‘1-12-95’
18. give account number and deposit amount of customer having account opened between dates 1-12-95 and 1-6-95
19. give name of the city where branch karolbagh is located
20. give details of customer anil

Join or Cartesian product :


1. give name of customer having living city Bombay and branch city delhi
2. give name of customers having the same living city as their branch city
3. give names of customers who are borrowers as well as depositors and having living city nagpur
4. give names of customers who are depositors and have the same branch city as that of sunil
5. give names of depositors having the same living city as that of shivani and having deposit amount greater than
2000
6. give names of borrowers having deposits amount greater than 1000 and loan amount greater than 2000
7. give names of depositors having the same branch as the branch of sunil
8. give names of borrowers having loan amount greater than the loan amount of anil
9. give names of customers living in the city where branch of depositor sunil is located
10. give loanno and loan amount of barrowers having the same branch as that of depositor sunil
11. give loadno, load amount, account no and deposit amount of customers living in city nagpur
12. give loadno, loan amount, account no and deposit amount of customers having deposit branch located in delhi
13. give loanno, loan amount, account no, deposit amount, branch name, branch city and living city of Pramod
14. give deposit details and loan details of customer in the city where Promod is living
15. give names of depositors having the same branch city as that of sunil and having the same living city as that of
anil
16. give names of depositors having amount greater than 1000 and having the same living city as Pramod
17. give city of customer having the same branch city as that of promod
18. give branch city and living city of Promod
19. give branch city of a sunil or branch city of anil
20. give the living city of anil and the living city of sunil

Aggregate funcations :

1. List total loan


2. List total deposit
3. List total loan taken from ANDHERI branch
4. List total deposit of customer having account date later than 01-jan-96
5. list total deposit of customer living in city nagpur
6. list maximum deposit of customers living BOMBAY
7. list total deposit of customers having branch city DELHI
8. list total deposit of customers living in the city where sunil in living
9. count total number of branch cities
10. count total number of customer cities
11. give branch name and branchwise deposit
12. give city name and citywise deposit
13. give cityiwise name and branchwise deposit
14. give the branchwise deposit of customer after account date 01-jan-96
15. give branchwise load of customer living in nagpur
16. count total number of customers
17. count total number of depositors branchwise
18. give maximum load from branch vrce
19. give living citywise load of borrowers
20. give the number of customers who are depositors as well as borrowers

Group by and Having Clause :


1. list the branches having sum of deposit more than 4000
2. list the branches having a sum of deposit more than 1000 and located in city BOMBAY
3. list the names of customers having deposit in the branches where the average deposit is more than 1000
4. list the names of customers having maximum deposit
5. list the name of customers having maximum deposit in the customers living in NAGPUR
6. list the name of branch having highest number of depositors
7. count the number of depositors living in NAGPUR
8. give names of customers in POWAI branch having more deposit than all customer from VRCE branch
9. give names of customers in KAROLBAGH branch having more deposit than any other customer in VIRAR
branch
10. give names of customers having highest deposit in the branch where sunil is having deposit
11. give the highest deposit of the city where branch of sunil is located
12. give names of customers having more deposit than the average deposit in their respective branches
13. give names of customers having maximum deposit amount deposits of NAGPUR for branch VRCE
14. give the name of branch where number of depositors is less than 2
15. give name of city having more customers living in than NAGPUR
16. give names of branches having the number of depositors more than the number of borrowers
17. give the names of cities in which the maximum number of branches are located
18. give the names of customers living in the city where the maximum number of depositors are located
19. give the names of borrowers having the same branch city and highest borrower
20. count the number of customers living in city where branch is located

Update Statements :

1. give 10% interest to all depositors


2. give 10% interest to all depositors living in NAGPUR
3. give 10% interest to all depositors living in NAGPUR
4. give 10% interest to all depositors living in NAGPUR and having branch in city BOMBAY
5. add hundred rupees to the deposit of ANIL and assign it to SUNIL
6. change the deposit of VRCE branch to 1000 and change the branch as VRCE_AMBAZARI
7. assign to the deposit of ANIL the maximum deposit from VRCE branch
8. change the living city of VRCE branch borrowers to NAGPUR
9. update deposit of ANIL give him maximum deposit from depositors in living city NAGPUR
10. deposit the sum of the deposits of SUNIL and VIJAY in the account of ANIL
11. transfer Rs 10 from the account of ANIL to the account of SUNIL
12. transfer Rs 10 from the account of ANIL to the account of SUNIL if both are having the same branch
13. transfer Rs 10 from the account of MADHURI to the account of PRAMOD if both are living in NAGPUR
14. transfer Rs 10 from the account of MADHURI to the account of PRAMOD if both are living in the same city
15. transfer Rs 10 from the account of ANIL to the account of SUNIL if both are having the same branches
16. add Rs 100 to the account of all those depositors who are having the highest deposit amount in their respective
branches
17. add Rs 10 to the amount of all depositors having deposit higher than the average deposit
18. add Rs 10 to the amount of all depositors having deposit higher than the average deposit of their branch
19. add Rs 10 to the amount of all customers living in the city where their branch is located
20. add Rs 10 to the amount of all depositors having deposit higher than the average deposit of their branch

Delete Statement :
1. delete from customer
2. delete depositors of branches having number of customers between 1 and 3
3. delete branches having average deposit less than 5000
4. delete branches having maximum loan more than 5000
5. delete branches having deposit from NAGPUR
6. delete deposit of ANIL and SUNIL if both are having branch VIRAR
7. delete deposit of ANIL and SUNIL if both are having living city NAGPUR
8. delete deposit of ANIL and SUNIL if both are having the same living city
9. delete deposit of ANIL and SUNIL if they are having less deposit than VIJAY
10. delete deposit of VIJAY
11. delete deposit of AJAY if VIJAY is not a depositor
12. delete customers from BOMBAY city
13. delete depositors if the branch is VIRAR and depositor name is AJAY
14. delete depositors having deposit less than 500
15. delete borrower having loan more than 10000
16. delete borrower having loan more than 1000 and branch KAROLBAGH
17. delete the names of those depositors of VRCE branch who live in the city BOMBAY
18. delete borrower having branch name CHANDHI
19. delete borrower of branches having average loan less than 1000
20. delete borrower of branches having the minimum number of customers

Set operators :
1. list all the customers who are depositors but not borrowers
2. list all the customers who are both depositors and borrowers
3. list all the customers along with their amount who are either borrowers or depositors and living in city NAGPUR
4. list all the depositors having deposit in all the branches where SUNIL is having account
5. list all the customers living in city NAGPUR and having branch city BOMBAY or DELHI
6. list all the depositors living in city NAGPUR
7. list all the depositors living in NAGPUR and having branch in city DELHI
8. list the branch cities of ANIL and SUNIL
9. list the customer having deposit greater than 1000 and loan less than 10000
10. list the borrowers having branch city same as that of SUNIL
11. list the cities of depositors having branch VRCE
12. list the depositors having the same living city as that of SUNIL and the same branch city as that of ANIL
13. list the depositors having amount less than 8000 and living in the same city as Ms. SHIVANI
14. list all the customers who are both depositors and borrowers and living in the same city as ANIL
15. list all the cities where branches of ANIL and SUNIL are located
16. list all the customer names and the AMOUNT for depositors living in the city where either ANIL or SUNIL is
living
17. list the amount for the depositors living in the city where ANIL is living
18. list the cities which are either branch city of ANIL or living city of SUNIL
19. list the customers who are borrowers or depositors and having living city BOMBAY and branch city same as that
of SANDIP
20. list the customers who are both borrowers and depositors and having the same branch city as that of ANIL

Scalar Subquery In select clause :


1. comparing the salary of employee with the maximum salary of employee in that company
Use of scalar subquery in where clause :
1. Display names of employees having maximum salary in his company
Use of scalar subquery in order by clause :
1. displaying employees ordered by maximum salary in their company

Simple Case Statement :


EMP_SHIFT
Ename Shift
Anil A
Shankar B
C
D

Using case .. when .. else


Select ename,
(CASE shift
When ‘A’ then ‘A-SHIFT’
When ‘B’ then ‘B-SHIFT’
When ‘C’ then ‘C-SHIFT’
ELSE
‘ANY_SHIFT’
END) as Shift_Name
FROM
Emp_Shift;
Searched Case Statement :
SELECT ENAME,
(CASE
WHEN shift < ‘C’ THEN ‘MORNING_SHIFT’
WHEN shift < ‘D’ THEN ‘MORNING_SHIFT’
ELSE
‘NIGHT_SHIFT’
END) AS SHIFT_NAME
FROM
EMP_SHIFT;

Query’s based on operators :

1. Display empno, ename, sal ,annual sal, daily sal from all employees in the descending order of daily
salary ?
2. Display empno,ename, joining date, current date, experience of all employees in desc of experience
3. Display empno,ename, joining date, current date, experience show in years of all employees in desc of
experience
4. Display empno,ename, ta, da, hra, total , gross salary, of all the employees in desc order of gross
salary
5. Display the details of clerks
6. Display details of ename of scott
7. list the employees whose sal is more than 2500
8. list the employees whose joined after year 98
9. Display the employees whose experience more than 26 years
10. Display the details of all the employee receiving a daily salary less then 50
11. Display all the details with experience > 26
12. Display the employee details working for the deptno 30 ? in the desc order by job
13. Display all the employees joined before 1st –MAY-194
14. Display all the analysts & Managers
15. Display the details of blake, king, james, john’s adams, and killer
16. Display the details of all the employees joined on 17-nov-1981 , 03-dec-1981, 09-jun-1981
17. Display the details of all the employees whose salary is ranging from 1500 to 3250 (write 2 methods )
18. Display the details of all the employees in desc order of their salary of those joining in the year 1981
19. Display the details of manager along with exp of those having ranges from 26 to 27
20. Display the details of all the employees receiving no comm.
21. Display the details of all the employees receiving the comm.
22. Display the details off all the employees joined after 2nd quarter of 1982
23. Display all 4 character names
24. Display all the 5 character names begin with ‘S’
25. Display all the names having character ‘A’
26. List all the names ending with character ‘N’
27. List all the employees joined in month which started with character ‘A’
28. Display the details of all 4 digits salary employees
29. Display all the table names having a character underscore in the name
30. Display all the table names of having percentile character in the name
31. Display all the table names of having space character in the name
32. Display the details of all the manages of dept 10,20,30
33. Display all the salesman of deptno 30 receiving some comm.
34. Display the details of all analyst having exp more than 25 years receiving a salary which is more than
2000 & not receiving any comm. In the desc order of hiredate
35. Display the details of all the employees of dept 10 & 20 joined before 1983, with sal more than 1300 &
less than 3500 and not belongs to the month December working under some manager with out comm.
Or who belongs to dept 30 working as salesman with sal more than 800 joined in the year 1981 & name
of the employee not starts with character ‘A’ in the ascending order of deptno
36. Display empno, ename, sal daily sal, rounded to the nearest integer annual sal rounded to the nearest
100, experience with 2 decimal places of all the employees
37. Display the details of all the employees along with daily sal of those receiving a dsal without
any decimal places
38. Display empno, ename, sal, comm., sal or comm. Which even in high sal or comm. Which ever is low
for all the employees.
39. Display all the salaries those are divisible by 1000
40. Display all the even number salaries
41. Display all 6 charactered named employees
42. Display the emp names those are starting with ‘S’ and 5 characters length and 3rd character is ‘O’ and
last character is ‘T’
43. Display all enames having a char eighter a,e,I,o,u in the 3rd position of name
44. Display empno,ename, sal, dailysal, of all employees in the descending order of their daily salary

Projection : Retrieving the data from the specific columns of table is called projection

Alias : means giving a temporary heading to column during the data display is called columns alias
1. Display empno, ename, sal, job of all employees descriptive line headings (use “as” also)

Order by clause : sorting the output (default sort order is asc / desc)
Syntax :
1. Display details of employee in the descending order of their salaries
2. Display details of employee in the descending order of their experience
3. Display deptno, job, empno, sal , of all the employees in the ascending order of deptno & in desc order
of job (1,2)
4. Display all the unique jobs in ascending order
5. Display all the commission in descending order

NVL( ) : null value conversion


Nvl ( ) is to replace the null value with specified not null value
Nvl(<col>, <value>) this function required 2 parameters
This function works on any datatype, both parameters along with datatype

Decode( ) :
Decode works on any datatype but all parameters should belongs to same datatype

9i Extrace (day from sysdate) :

Case( ) :
1. Display details of employees if current day of month is lessthan 15 then consider the total days of
lastmonth otherwise totaldays of present month

Lpad, rpad, trim, Ltrim, rtrim,


Date converssion functions

Das könnte Ihnen auch gefallen