Daatabasemgmtassignment 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

ASSIGNMENT 1

SQL> create table employee_007(emp_no number(5) primary key,emp_name varchar(30)

,designation varchar(10),date_of_join date, salary number,dept_no number(11));

Table created.

SQL> desc employee_007

Name Null? Type

----------------------------------------- -------- ----------------------------

EMP_NO NOT NULL NUMBER(5)

EMP_NAME VARCHAR2(30)

DESIGNATION VARCHAR2(10)

DATE_OF_JOIN DATE

SALARY NUMBER

DEPT_NO NUMBER(11)

SQL> CREATE TABLE department_007(dept_no number(11) primary key , dept_name varchar(

30),dept_loc varchar(20));

Table created.

SQL> desc department_007;

Name Null? Type

----------------------------------------- -------- ----------------------------

DEPT_NO NOT NULL NUMBER(11)

DEPT_NAME VARCHAR2(30)

DEPT_LOC VARCHAR2(20)

SQL> create table allowance_007(designation varchar(10),sp_allowance_007 number,

conveyance number);

Table created.

SQL> desc allowance_007;

Name Null? Type

----------------------------------------- -------- ----------------------------


DESIGNATION VARCHAR2(10)

SP_ALLOWANCE_007 NUMBER

CONVEYANCE NUMBER

SQL> insert into employee_007

2 values(&emp_no,&emp_name,&designation,&date_of_join,&salary,&dept_no);

Enter value for emp_no: 1000

Enter value for emp_name: 'robert'

Enter value for designation: 'officer'

Enter value for date_of_join: '01-dec-1985'

Enter value for salary: 1000

Enter value for dept_no: 10

old 2: values(&emp_no,&emp_name,&designation,&date_of_join,&salary,&dept_no)

new 2: values(1000,'robert','officer','01-dec-1985',1000,10)

1 row created.

SQL> /

Enter value for emp_no: 10002

Enter value for emp_name: 'allan'

Enter value for designation: 'clerk'

Enter value for date_of_join: '14-may-1982'

Enter value for salary: 5000

Enter value for dept_no: 10

old 2: values(&emp_no,&emp_name,&designation,&date_of_join,&salary,&dept_no)

new 2: values(10002,'allan','clerk','14-may-1982',5000,10)

1 row created.
SQL> /

Enter value for emp_no: 10003

Enter value for emp_name: 'martin'

Enter value for designation: 'manager'

Enter value for date_of_join: '23-dec-1984'

Enter value for salary: 3500

Enter value for dept_no: 20

old 2: values(&emp_no,&emp_name,&designation,&date_of_join,&salary,&dept_no)

new 2: values(10003,'martin','manager','23-dec-1984',3500,20)

1 row created.

SQL> /

Enter value for emp_no: 10004

Enter value for emp_name: 'james'

Enter value for designation: 'analyst'

Enter value for date_of_join: '22-jul-1990'

Enter value for salary: 5000

Enter value for dept_no: 30

old 2: values(&emp_no,&emp_name,&designation,&date_of_join,&salary,&dept_no)

new 2: values(10004,'james','analyst','22-jul-1990',5000,30)

1 row created.

SQL> /

Enter value for emp_no: 10005

Enter value for emp_name: 'john'

Enter value for designation: 'analyst'


Enter value for date_of_join: '22-jul-1990'

Enter value for salary: 4900

Enter value for dept_no: 30

old 2: values(&emp_no,&emp_name,&designation,&date_of_join,&salary,&dept_no)

new 2: values(10005,'john','analyst','22-jul-1990',4900,30)

1 row created.

SQL> /

Enter value for emp_no: 10006

Enter value for emp_name: 'jones'

Enter value for designation: 'clerk'

Enter value for date_of_join: '16-apr-1986'

Enter value for salary: 950

Enter value for dept_no: 30

old 2: values(&emp_no,&emp_name,&designation,&date_of_join,&salary,&dept_no)

new 2: values(10006,'jones','clerk','16-apr-1986',950,30)

1 row created.

SQL> insert into department_007 values (&dept_no,&dept_name,&dept_loc);

Enter value for dept_no: 20

Enter value for dept_name: 'accounts'

Enter value for dept_loc: 'america'

old 1: insert into department_007 values (&dept_no,&dept_name,&dept_loc)

new 1: insert into department_007 values (10,'accounts','america')

1 row created.

SQL> insert into department_007 values(&dept_no,&dept_name,&dept_loc);

Enter value for dept_no: 10

Enter value for dept_name: 'marketing'

Enter value for dept_loc: 'london'


old 1: insert into department_007 values(&dept_no,&dept_name,&dept_loc)

new 1: insert into department_007 values(10,'marketing','london')

1 row created.

SQL> /

Enter value for dept_no: 20

Enter value for dept_name: 'accounts'

Enter value for dept_loc: 'america'

old 1: insert into department_007 values(&dept_no,&dept_name,&dept_loc)

new 1: insert into department_007 values(20,'accounts','america')

1 row created.

SQL> /

Enter value for dept_no: 30

Enter value for dept_name: 'sales'

Enter value for dept_loc: 'new york'

old 1: insert into department_007 values(&dept_no,&dept_name,&dept_loc)

new 1: insert into department_007 values(30,'sales','new york')

1 row created.

SQL> /

Enter value for dept_no: 40

Enter value for dept_name: 'software'

Enter value for dept_loc: 'boston'

old 1: insert into department_007 values(&dept_no,&dept_name,&dept_loc)

new 1: insert into department_007 values(40,'software','boston')

1 row created.

SQL> /

Enter value for dept_no: 50

Enter value for dept_name: 'production'


Enter value for dept_loc: 'boston'

old 1: insert into department_007 values(&dept_no,&dept_name,&dept_loc)

new 1: insert into department_007 values(50,'production','boston')

1 row created.

SQL> insert into allowance_007 values(&designation,&sp_allowance,&conveyance);

Enter value for designation: 'manager'

Enter value for sp_allowance: 1000

Enter value for conveyance: 500

old 1: insert into allowance_007 values(&designation,&sp_allowance,&conveyanc

new 1: insert into allowance_007 values('manager',1000,500)

1 row created.

SQL> /

Enter value for designation: 'officer'

Enter value for sp_allowance: 800

Enter value for conveyance: 400

old 1: insert into allowance_007 values(&designation,&sp_allowance,&conveyanc

new 1: insert into allowance_007 values('officer',800,400)

1 row created.

SQL> /

Enter value for designation: 'analyst'

Enter value for sp_allowance: 1200

Enter value for conveyance: 500

old 1: insert into allowance_007 values(&designation,&sp_allowance,&conveyanc


)

new 1: insert into allowance_007 values('analyst',1200,500)

1 row created.

SQL> /

Enter value for designation: 'clerk'

Enter value for sp_allowance: 500

Enter value for conveyance: 300

old 1: insert into allowance_007 values(&designation,&sp_allowance,&conveyanc

new 1: insert into allowance_007 values('clerk',500,300)

1 row created.
Connected.

SQL> select * from employee_007;

EMP_NO EMP_NAME DESIGNATIO DATE_OF_JOIN SALARY DEPT_NO

---------- ------------------------------ ---------- --------- --------------------------------------

1000 robert officer 01-DEC-85 1000 10

10002 allan clerk 14-MAY-82 5000 10

10003 martin manager 23-DEC-84 3500 20

10004 james analyst 22-JUL-90 5000 30

10005 john analyst 22-JUL-90 4900 30

10006 jones clerk 16-APR-86 950 30

6 rows selected.

SQL> select * from department_007;

DEPT_NO DEPT_NAME DEPT_LOC

---------- ------------------------------ --------------------

10 marketing london
20 accounts america

30 sales new york

40 software boston

50 production boston

SQL> select * from allowance_007;

DESIGNATIO SP_ALLOWANCE_007 CONVEYANCE

---------- ---------------- ----------

manager 1000 500

officer 800 400

analyst 1200 500

clerk 500 300


QUESTIONS:
Q1: LIST ALL EMPLOYEES BELONGING TO DEPARTMENT20 IN DEPARTMENT_007

SQL> select * from employee_007 where dept_no=20;

EMP_NO EMP_NAME DESIGNATIO DATE_OF_JOIN SALARY DEPT_NO

----------------------------------------------------------------------------------------------------------------

10003 martin manager 23-DEC-84 3500 20

Q2.LIST THE EMPLOYEES WHO ARE EARNING MORE THEN 1200 BUT LESS THAN 4000.

SQL> select * from employee_007 where salary between 1200 and 4000;

EMP_NO EMP_NAME DESIGNATIO DATE_OF_JOIN SALARY DEPT_NO

-----------------------------------------------------------------------------------------------------------

10003 martin manager 23-DEC-84 3500 20

Q3. List the employees who have joined after 1st jan 1984 in order of the joining date.

SQL> select * from employee_007 where date_of_join>'01-jan-1984'order by date_of

_join;

EMP_NO EMP_NAME DESIGNATIO DATE_OF_JOIN SALARY DEPT_NO

-----------------------------------------------------------------------------------------------------

10003 martin manager 23-DEC-84 3500 20

1000 robert officer 01-DEC-85 1000 10

10006 jones clerk 16-APR-86 950 30

10005 john analyst 22-JUL-90 4900 30

10004 james analyst 22-JUL-90 5000 30

Q4.list the employees who are either managers or officers

SQL> select * from employee_007 where (designation='officer'or designation='mana

ger');
EMP_NO EMP_NAME DESIGNATIO DATE_OF_JOIN SALARY DEPT_NO

-------------------------------------------------------------------------------------------------------

1000 robert officer 01-DEC-85 1000 10

10003 martin manager 23-DEC-84 3500 20

Q5.list the emolyees located in new York

SQL> select employee_007.emp_no,employee_007.emp_name,employee_007.designation,employee_007.dept_no


from employee_007,department_007 where employee_007.dept_no=department_007.dept_no and
department_007.dept_loc='new york' ;

EMP_NO EMP_NAME DESIGNATIO DEPT_NO

---------- ------------------------------ ---------- ----------

10004 james analyst 30

10005 john analyst 30

10006 jones clerk 30

Q6.list the employees who are in the sales department.

SQL> select employee_007.emp_no,employee_007.emp_name,employee_007.designation,e

mployee_007.dept_no,department_007.dept_no from employee_007,department_007 wher

e employee_007.dept_no=department_007.dept_no and department_007.dept_name='sale

s';

EMP_NO EMP_NAME DESIGNATIO DEPT_NO DEPT_NO

---------- ------------------------------ ---------- ---------- ----------

10004 james analyst 30 30

10005 john analyst 30 30

10006 jones clerk 30 30


Q7.list the departments that do not have employees.

SQL> select department_007.dept_no,department_007.dept_name from department_007

where dept_no not in(select dept_no from employee_007 );

DEPT_NO DEPT_NAME

---------- ------------------------------

40 software

50 production

Q8.list the employees who are earning more than Robert.

SQL> select * from employee_007 where salary >(select salary from employee_007 w

here emp_name='robert');

EMP_NO EMP_NAME DESIGNATIO DATE_OF_J SALARY DEPT_NO

-------------------------------------------------------------------------------------------------

10002 allan clerk 14-MAY-82 5000 10

10003 martin manager 23-DEC-84 3500 20

10004 james analyst 22-JUL-90 5000 30

10005 john analyst 22-JUL-90 4900 30

Q9.find how many employees are there in the organization.

SQL> select count(*) from employee_007;

COUNT(*)

----------

6
Q10. Find how many employees are working in sales department

SQL> select count(*) from employee_007,department_007 where employee_007.dept_no

=department_007.dept_no and department_007.dept_name='sales';

COUNT(*)

----------

Q11. Find out the total salaries paid to the employees.

SQL> select sum(employee_007.salary + allowance_007.sp_allowance_007 + allowance

_007.conveyance)from employee_007,allowance_007 where employee_007.designation=a

llowance_007.designation;

SUM(EMPLOYEE_007.SALARY+ALLOWANCE_007.SP_ALLOWANCE_007+ALLOWAN
CE_007.CONVEYANCE)

--------------------------------------------------------------------------------

28050

Q12.what si the average salary paid to the employees.

SQL> select avg(employee_007.salary + allowance_007.sp_allowance_007 + allowance

_007.conveyance)from employee_007,allowance_007 where employee_007.designation=a

llowance_007.designation;
AVG(EMPLOYEE_007.SALARY+ALLOWANCE_007.SP_ALLOWANCE_007+ALLOWAN
CE_007.CONVEYANCE)

--------------------------------------------------------------------------------

4675

Q13.what is the minimum salary paid in the department 30.

SQL> select min(employee_007.salary + allowance_007.sp_allowance_007 + allowance

_007.conveyance)from employee_007,allowance_007 where employee_007.designation=a

llowance_007.designation and employee_007.dept_no=30;

MIN(EMPLOYEE_007.SALARY+ALLOWANCE_007.SP_ALLOWANCE_007+ALLOWAN
CE_007.CONVEYANCE)

--------------------------------------------------------------------------------

1750

Q14.display the names and grades of employees based on their designation

SQL> select emp_name,designation, DECODE(designation,'manager','A','officer','B'

,'analyst','C','clerk','D')grade from employee_007;

EMP_NAME DESIGNATIO G
------------------------------ ---------- -

robert officer B

allan clerk D

martin manager A

james analyst C

john analyst C

jones clerk D

6 rows selected.

Q15.display employee names and date of join ,joining date should be in the format
’26,january1998’.

SQL> select emp_name,to_char(date_of_join,'fmDD month yyyy')as date_of_join from

employee_007;

EMP_NAME DATE_OF_JOIN

------------------------------ -----------------

robert 1 december 1985

allan 14 may 1982

martin 23 december 1984

james 22 july 1990

john 22 july 1990

jones 16 april 1986

6 rows selected.

Q16. Find how long an employee has worked in terms of year,month,days.


SQL> select emp_name,designation,(sysdate-date_of_join)as days,(sysdate-date_of_

join)/31 as months,(sysdate-date_of_join)/365 as years from employee_007;

EMP_NAME DESIGNATIO DAYS MONTHS YEARS

------------------------------ ---------- ---------- ---------- ----------

robert officer 9061.73344 292.313982 24.826667

allan clerk 10358.7334 334.152692 28.3800916

martin manager 9404.73344 303.378498 25.766393

james analyst 7367.73344 237.668821 20.1855711

john analyst 7367.73344 237.668821 20.1855711

jones clerk 8925.73344 287.926885 24.4540642

Q17.display total salary department wise

SQL> select sum(employee_007.salary + allowance_007.sp_allowance_007 + allowance

_007.conveyance)as total_salary from employee_007,allowance_007 where employee_0

07.designation=allowance_007.designation group by dept_no;

TOTAL_SALARY

------------

15050

5000

8000

Q18.display the maximum salaries in each department. Along with the name of the department.
SQL> select department_007.dept_name,max(salary) from department_007,employee_00

7 where department_007.dept_no=employee_007.dept_no group by dept_name;

DEPT_NAME MAX(SALARY)

------------------------------ -----------

accounts 3500

sales 5000

marketing 5000

Q19.display the total salary of each (salary+sp+allowance_007 -conveyance)of each employee in


order of total salary

SQL> select employee_007.emp_name,sum(employee_007.salary + allowance_007.sp_all

owance_007 - allowance_007.conveyance)as total_salary from employee_007,allowanc

e_007 where employee_007.designation=allowance_007.designation group by emp_name

EMP_NAME TOTAL_SALARY

------------------------------ ------------

allan 5200

robert 1400

james 5700

john 5600

jones 1150

martin 4000

6 rows selected.
Q20 give the details of employee with the second highest salary.

SQL> select * from employee_007 where salary=(select max(salary)from employee_00

7 where salary<(select max(salary) from employee_007));

EMP_NO EMP_NAME DESIGNATIO DATE_OF_J SALARY

---------- ------------------------------ ---------- --------- ----------

DEPT_NO

----------

10005 john analyst 22-JUL-90 4900

30

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy