Anda di halaman 1dari 22

UNF Data

Patient no patient name doctor code


1 Santosh
NA
2 Bindhu
NA
3 Ravi
NA
4 Bindhu
JO
5 Santosh
AN
6 Santosh
JA
7 Ravi
JO

doctor name
Natraj
Natraj
Natraj
Jonathan
Anuja
Jason
Jonathan

surgery
Shoulder
Spine
Shoulder
Spine
Brain
Knee
Hip

First Normal Form


Sr No

Patient ID
1 SR01
2 BR01
3 RG01
4 BR01
5 BR01
6 BR01
7 SR01
8 SR01
9 SR01
10 SR01
11 RG01
12 RG01

Second Normal Form


FK
Patient ID
SR01
BR01
RG01
BR01
BR01
BR01
SR01
SR01
SR01
SR01
RG01
RG01
PK

Patient Name Doctor code Doctor name


Santosh
NA
Natraj
Bindhu
NA
Natraj
Ravi
NA
Natraj
Bindhu
JO
Jonathan
Bindhu
JO
Jonathan
Bindhu
JO
Jonathan
Santosh
AN
Anuja
Santosh
AN
Anuja
Santosh
JA
Jason
Santosh
JA
Jason
Ravi
JO
Jonathan
Ravi
JO
Jonathan

PK
Invoice no
101
102
103
104
302
425
105
110
106
122
107
108
FK

Patient ID
SR01
BR01
RG01

First Name
Santosh
Bindhu
Ravi

FK
doctor code
NA01
JO01
AN01
JA01

PK
doctor name
Natraj
Jonathan
Anuja
Jason

PK
surgery
Shoulder
Spine
Brain
Knee
Hip

FK
Surgery ID
SXSH01
SXSP01
SXBR01
SXKN01
SXHI01

Last Name
Raju
Reddy
Guddipalli

DOB
21-Dec
8-Sep
1-Jan

PK
diagnosis
Shoulder disloc
slip disc
ligament tear
TB
Psoriosis
haemorage
Tumour
Replacement
Rupture

date

diagnosis
20-Jan Shoulder dislocation
23-Jan slip disc
27-Jan ligament tear
Jan/20 Feb/ 03 Apr
slip disc/TB/Psoriosis
Jan/20Jan
haemorage/Tumour
Jan/15Mar
Replacement/Ligament tear
Jan/ 04/03
Rupture/Ligament tear

cost

23
20
20
20

25000
30000
5000
30000/45000/55000
80000/100000
15000/10000
15000/10000

Surgery
Shoulder
Spine
Shoulder
Spine
Spine
Spine
Brain
Brain
Knee
Knee
Hip
Hip

PK
invoice no

Surgery ID
SXSH01
SXSP01
SXSH01
SXSP01
SXSP01
SXSP01
SXBR01
SXBR01
SXKN01
SXKN01
SXHI01
SXHI01

Surgery ID
101 SXSH01
102 SXSP01
103 SXSH01
104 SXSP01
302 SXSP01
425 SXSP01
105 SXBR01
110 SXBR01
106 SXKN01
122 SXKN01
107 SXHI01
108 SXHI01

Diagnosis
Shoulder dislocation
slip disc
ligament tear
slip disc
TB
Psoriosis
haemorage
Tumour
Replacement
Ligament tear
Rupture
Ligament Tear

Diagnosis ID
SD01
SL01
LG01
SL01
TB01
PS01
HM01
TU01
RE01
LG01
RU01
LG01
PK

Location
GA
TX
NJ

FK
Diagnosis ID
SD01
SL01
LG01
TB01
PS01
HM01
TU01
RE01
RU01

surgery
Shoulder
Spine
Spine
Hip
Brain
Knee

invoice no

invoice date
101
102
103

104/302/425
105/110
106/122
107/Cash

24
21
21
21

Diagnosis ID
SD01
SL01
LG01
SL01
TB01
PS01
HM01
TU01
RE01
LG01
RU01
LG01

Date

Invoice date

Date
21-Jan
24-Jan
28-Jan
24-Jan
21-Feb
4-Apr
21-Jan
21-Jan
21-Jan
16-Mar
21-Jan
4-Apr

PK

Jan/21
Jan/21
Jan/16
Jan/04

21-Jan
24-Jan
28-Jan
Feb/04 Apr
Jan
Mar
Apr

PK
Cost
invoice noinvoice date
20-Jan
25000
101
21-Jan
23-Jan
30000
102
24-Jan
27-Jan
5000
103
28-Jan
23-Jan
30000
104
24-Jan
20-Feb
45000
302
21-Feb
3-Apr
55000
425
4-Apr
20-Jan
80000
105
21-Jan
20-Jan
100000
110
21-Jan
20-Jan
15000
106
21-Jan
15-Mar
10000
122
16-Mar
20-Jan
15000
107
21-Jan
3-Apr
10000
108
4-Apr

Cost
20-Jan
25000
23-Jan
30000
27-Jan
5000
23-Jan
30000
20-Feb
45000
3-Apr
55000
20-Jan
80000
20-Jan
100000
20-Jan
15000
15-Mar
10000
20-Jan
15000
3-Apr
10000

doctor code
NA01
NA01
JO01
JO01
AN01
JA01

SQL QUERIES

5. Display the employee no and total salary for all the employees
6. Display the employee name and annual salary for all employees.

8. Display the names of all the employees who are working as clerks and drawing a salary m
10.
11.
12.
13.

Display
Display
Display
Display

the
the
the
the

employee number and name who do not earn any comm.


names of employees who are working as clerks, salesman or analyst and dr
names of the employees who are working in the company for the past 5 ye
list of employees who have joined the company before 30-JUN-90 or after 3

15. Display the list of all users in your database (use catalog table).

17. Display the name of the current user.


18. Display the names of employees working in depart number 10 or 20 or 40or employees

21.
22.
23.
24.
25.

Display the names of employees whose names have second alphabet A in their names.
Select the names of the employee whose names is exactly five characters in length.
Display the names of the employee who are not working as MANAGERS.
Display the names of the employee who are not working as SALESMAN OR CLERK OR A
Display all rows from EMP table. The system should wait after every screen full of inform

27. Display the total salary being paid to all Employees.

31.
32.
33.
34.
35.

Display
Display
Display
Display
Display

the
the
the
the
the

maximum salary being paid to CLERK.


maximum salary being paid to depart number 20.
minimum salary being paid to any SALESMAN.
average salary drawn by MANAGERS.
total salary drawn by ANALYST working in depart number 40.

41. Display name, salary, hra, pf, da, total salary for each employee. The output should be
43. Display the various jobs and total number of employees within each job group.

45. Display the depart numbers and max salary for each department.

48.
49.
50.
51.
52.
53.
54.
55.
56.

Display
Display
Display
Display
Display
Display
Display
Display
Display

the
the
the
the
the
the
the
the
the

depart numbers with more than three employees in each dept.


various jobs along with total salary for each of the jobs where total salary is
various jobs along with total number of employees in each job. The output s
name of the employee who earns highest salary.
employee number and name for employee working as clerk and earning hig
names of salesman who earns a salary more than the highest salary of any
names of clerks who earn a salary more than the lowest salary of any sales
names of the employees who earn highest salary in their respective depart
names of the employees who earn highest salaries in their respective job g

59. Display the Job groups having total salary greater than the maximum salary for manage
60. Display the names of employees from department number 10 with salary greater than
61. Display the names of the employees from department number 10 with salary greater th
62. Display the names of the employees in Uppercase.
63. Display the names of the employees in Lowercase.
64. Display the names of the employees in uppercase.
65. Display the length of your name using appropriate function.
66. Display the length of all the employee names.
67. Select name of the employee concatenate with employee number.
68. User appropriate function and extract 3 characters starting from 2 characters from the
69. Find the First occurrence of character 'a' from the following string i.e 'Computer Mainten
70. Replace every occurrence of alphabet A with B in the string Allen (use translate function
71. Display the information from EMP table. Where job manager is found it should be displa
72. Display empno, ename, deptno from EMP table. Instead of display department numbers
73. Display your age in days.
74. Display your age in months.
75. Display the current date as 15th August Friday Nineteen Ninety Seven.
76. Display the following output for each row from EMP table. Scott has joined the company
77. Find the date for nearest Saturday after current date.
78. Display current time.
79. Display the date three months before the current date.
80. Display the common jobs from department number 10 and 20.
81. Display the jobs found in department 10 and 20 Eliminate duplicate jobs.
82. Display the jobs which are unique to department 10.
83. Display the details of those who do not have any person working under them.
84. Display the details of those employees who are in sales department and grade is 3.
85. Display those who are not managers and who are managers any one.
i) Display the managers names
ii) Display the who are not managers
86. Display those employee whose name contains not less than 4 characters.

87. Display those department whose name start with "S" while the location name ends with
88. Display those employees whose manager name is JONES.
89. Display those employees whose salary is more than 3000 after giving 20% increment.
90. Display all employees while their dept names;
91. Display ename who are working in sales dept.
92. Display employee name, deptname, salary and comm for those sal in between 2000 to
93. Display those employees whose salary greater than his manager salary.
94. Display those employees who are working in the same department where his manager
95. Display those employees who are not working under any manager.
96. Display grade and employees name for the dept no 10 or 30 but grade is not 4 while jo
97. Update the salary of each employee by 10% increment who are no eligible for commiss
98. SELECT those employee who joined the company before 31-dec-82 while their dept loca
99. DISPLAY EMPLOYEE NAME, JOB, DEPARTMENT, LOCATION FOR ALL WHO ARE WORKING A
100. DISPLAY THOSE EMPLOYEES WHOSE MANAGER NAME IS JONES? [AND ALSO DISPLAY T
101. Display name and salary of ford if his salary is equal to hisal of his grade
102. Display employee name, job, depart name, manager name, his grade and make out a
103. List out all employees name, job, salary, and grade and depart name for everyone in t
104. Display the employee name, job and his manager. Display also employee who are with
105. Find out the top 5 earners of company?
106. Display name of those employee who are getting the highest salary?
107. Display those employee whose salary is equal to average of maximum and minimum?
108. Select count of employee in each department where count greater than 3?
109. Display dname where at least 3 are working and display only department name?
110. Display name of those managers name whose salary is more than average salary of h
111. Display those managers name whose salary is more than average salary of his employ
112. Display employee name, sal, comm and net pay for those employee whose net pay is
113. Display all employees names with total sal of company with each employee name?
114. Find out last 5(least) earners of the company?
115. Find out the number of employees whose salary is greater than their manager salary?
116. Display those department where no employee working?
117. Display those employee whose salary is ODD value?
118. Display those employee whose salary contains at least 3 digits?
119. Display those employee who joined in the company in the month of Dec?
120. Display those employees whose name contains "A"?
121. Display those employee whose deptno is available in salary?
122. Display those employee whose first 2 characters from hiredate -last 2 characters of sa
123. Display those employee whose 10% of salary is equal to the year of joining?
124. Display those employee who are working in sales or research?
125. Display the grade of jones?
126. Display those employees who joined the company before 15 of the month?
127. Display those employee who has joined before 15th of the month.
128. Delete those records where no of employees in a particular department is less than 3.
129. Display the name of the department where no employee working.
130. Display those employees who are working as manager.
131. Display those employees whose grade is equal to any number of sal but not equal to fi

132. Print the details of all the employees who are Sub-ordinate to BLAKE?
133. Display employee name and his salary whose salary is greater than highest average o
134. Display the 10th record of emp table(without using rowid)
135. Display the half of the ename's in upper case and remaining lowercase?
136. Display the 10th record of EMP table without using group by and rowid?
137. Create a copy of emp table;
138. Select ename if ename exists more than once.
139. Display all enames in reverse order?(SMITH:HTIMS).
140. Display those employee whose joining of month and grade is equal.
141. Display those employee whose joining DATE is available in deptno.
142. Display those employees name as follows
A ALLEN
B BLAKE
143. List out the employees ename, sal,PF(20% OF SAL) from emp;
144. Create table emp with only one column empno;
145. Add this column to emp table ename vrachar2(20).
146. Oops I forgot give the primary key constraint. Add in now.
147. Now increase the length of ename column to 30 characters.
148. Add salary column to emp table.
149. I want to give a validation saying that salary cannot be greater 10,000 (note give a na
150. For the time being I have decided that I will not impose this validation. My boss has ag
151. My boss has changed his mind. Now he doesn't want to pay more than 10,000. So rev
152. Add column called as mgr to your emp table;
153. Oh! This column should be related to empno. Give a command to add this constraint.
154. Add deptno column to your emp table;
155. This deptno column should be related to deptno column of dept table;
156. Give the command to add the constraint.
157. Create table called as newemp. Using single command create this table as well as get
158. Delete the rows of employees who are working in the company for more than 2 years.
159. Provide a commission (10% Comm of Sal) to employees who are not earning any comm
160. If any employee has commission his commission should be incremented by 10% of his
161. Display employee name and department name for each employee.
162. Display employee number, name and location of the department in which he is workin
163. Display ename, dname even if there are no employees working in a particular departm
164. Display employee name and his manager name.
165. Display the department name and total number of employees in each department
166. Display the department name along with total salary in each department.
167. Display itemname and total sales amount for each item.
168. Write a Query To Delete The Repeated Rows from emp table;
169. TO DISPLAY 5 TO 7 ROWS FROM A TABLE
170. DISPLAY TOP N ROWS FROM TABLE?
171. DISPLAY TOP 3 SALARIES FROM EMP;
172. DISPLAY 9th FROM THE EMP TABLE?
------******------

ks and drawing a salary more than 3000.

lesman or analyst and drawing a salary more than 3000.


mpany for the past 5 years;
fore 30-JUN-90 or after 31-DEC-90.

or 20 or 40or employees working as CLERKS, SALESMAN or ANALYST.

phabet A in their names.


characters in length.
ANAGERS.
LESMAN OR CLERK OR ANALYST.
every screen full of information.

umber 40.

e. The output should be in the order of total salary, hra 15% of salary,da 10% of salary, pf 5% salary, total salar
each job group.

n each dept.
jobs where total salary is greater than 40000.
in each job. The output should contain only those jobs with more than three employees.

g as clerk and earning highest salary among clerks.


he highest salary of any clerk.
owest salary of any salesman.
n their respective departments.
in their respective job groups.

ximum salary for managers.


with salary greater than that of any employee working in other department.
10 with salary greater than that of all employee working in other departments.

m 2 characters from the following string 'Oracle'. I.e. the output should be 'ac'.
ng i.e 'Computer Maintenance Corporation'.
en (use translate function)
found it should be displayed as boos (Use replace function).
lay department numbers display the related department name (Use decode function).

t has joined the company on Wednesday 13th August Ninten Ninety.

icate jobs.

ng under them.
ment and grade is 3.

characters.

location name ends with "K".


giving 20% increment.

e sal in between 2000 to 5000 while location is Chicago.

ment where his manager is work.

ut grade is not 4 while joined the company before 31-dec-82.


e no eligible for commission.
c-82 while their dept location is New York or Chicago.
ALL WHO ARE WORKING AS MANAGER?
S? [AND ALSO DISPLAY THEIR MANAGER NAME]?
of his grade
is grade and make out an under department wise?
rt name for everyone in the company except 'CLERK. Sort on salary display the highest salary?
o employee who are without manager?

maximum and minimum?


eater than 3?
department name?
than average salary of his company?
rage salary of his employee?
ployee whose net pay is greater than or equal to any other employee salary of the company?
ach employee name?

an their manager salary?

nth of Dec?

e -last 2 characters of salary?


year of joining?

of the month?

epartment is less than 3.

r of sal but not equal to first number of sal?

r than highest average of department number?

owercase?
and rowid?

er 10,000 (note give a name to this constraint)


alidation. My boss has agreed to pay more than 10,000.
more than 10,000. So revoke that salary constraint.

d to add this constraint.

e this table as well as get data into this table(use create table as);
ny for more than 2 years.
are not earning any commission.
cremented by 10% of his salary.

ent in which he is working.


ng in a particular department (use outer join).

s in each department
department.

5% salary, total salary will be(salary+hra+da)-pf.

Bindu paid
stone moun tr 51.36
food 12.82 Bin/Su
milk+ 11.62
domi 20.34
walmart 105.69
indiaplaz 57.34
starbucks
food amica
gas
water
parking
goodwill
milk
spicehut
aunt annes
hot breads Su/bin

51.36
12.82
11.62
20.34
105.69
57.34
8.45 Sa/Bin
26.7
25
7.08
5
8.15
6.67
5.01
9.8
10.47
371.5
71.5

Santosh
bawarchi 4
paradise 2
bawarchi 2
chettinad
liquor 37.4
stone moun
stone moun

692.51
392.51
130.8367
59.33667

41.15
29.94
23.3
23.87
37.43
15
10.29
180.98

common acount
stone moun tr 51.36
food 12.82 Bin/Su
domi 20.34
starbucks
aunt annes
hot breads Su/bin
stone mountain 15
stone mountai 10.29
chettinad 23.87
liquor 37.43
gokul
shell

Suyash
gokul
walmart
shell

51.36
12.82
20.34
8.45
9.8
10.47
15
10.29
23.87
37.43
53.12
27.58
280.53

53.12
59.33
27.58
140.03

300$ account
food amica
gas
water
parking
goodwill

natraj grocery/lunch
walmart
59.33
bawarchi 4
41.15
paradise 2
29.94
bawarchi 2
23.3
milk+ 11.
11.62
walmart 10
105.69
indiaplaz 5
57.34
spicehut
5.01
milk
6.67
340.05

00$ account

ery/lunch

26.7
25
7.08
5
8.15
71.93

Patient noDoctor noSurgery nDiag no


1
11
111
1111
1
33
333
6666
1
33
333
7777
1
44
444
3333
1
44
444
8888
2
11
222
2222
2
22
222
2222
2
22
222
4444
2
22
222
5555
3
11
111
3333
3
22
555
3333
3
22
555
9999