Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

SQL> create table employee(empid number(4),deptid number(2),empname varchar(25), empsalary

number(5));

Table created

SQL>insert into employee values(1000,10,’AAA’,50000);


1 row created
SQL>insert into employee values(1001,20,’BBB’,60000);
1 row created
SQL>insert into employee values(1002,30,’CCC’,80000);
1 row created
SQL>insert into employee values(1003,40,’DDD’,70000);
1 row created
SQL>insert into employee values(1004,20,’EEE’,40000);
1 row created

SQL> create table department(deptid number(2),deptname varchar(20), supervisor varchar(20));


Table created

SQL>insert into department values(10,’finance’,’www’);


1 row created
SQL>insert into department values(20,’accounts’,’xxx’);
1 row created
SQL>insert into department values(30,’sales’,’yyy’);
1 row created
SQL>insert into department values(40,’apprentice’,’zzz’);
1 row created

SQL>select * from employee;

EMPID DEPTID EMPNAME EMPSALARY


-------- ------------ ------------------ --------------
1000 10 AAA 50000
1001 20 BBB 60000
1002 30 CCC 80000
1003 40 DDD 70000
1004 10 EEE 40000

SQL>select * from department;

DEPTID DEPTNAME SUPERVISOR


-------- ------------------ ------------------
10 finance www
20 accounts xxx
30 sales yyy
40 apprentice zzz
SQL>select empname from employee where deptid=(select deptid from department where
deptname=’accounts’);

EMPNME
-------------
BBB
EEE
SQL>select count(*) from employee where deptid=(select deptid from department where
deptname=’accounts’);

COUNT(*)
---------------
2
SQL>select min(empsalary) from employee where deptid=(select deptid from department where
deptname=’accounts’);

MIN(EMPSALARY)
---------------------------
40000
SQL>select max(empsalary) from employee where deptid=(select deptid from department where
deptname=’accounts’);

MAX(EMPSALARY)
---------------------------
60000
SQL>select avg(empsalary) from employee where deptid=(select deptid from department where
deptname=’accounts’);

AVG(EMPSALARY)
---------------------------
50000
SQL>select * from employee where deptid=(select deptid from department where supervisor=’www’);

EMPID DEPTID EMPNAME SALARY


-------- ------------ ------------------ --------------
1000 10 AAA 50000

SQL>update employee set empsalary=empsalary+empsalary*0.15 where deptid=(select deptid from


department where deptname=’sales’);
1 row updated

SQL>alter table employee add(bonus number(5));


Table altered

SQL>update employee set bonus=empsalary*0.05;


5 rows updated
SQL> select * from employee;

EMPID DEPTID EMPNAME EMPSALARY BONUS


-------- ------------ ------------------ -------------- ---------------
1000 10 AAA 50000 2500
1001 20 BBB 60000 3000
1002 30 CCC 92000 4600
1003 40 DDD 70000 3500
1004 20 EEE 40000 2000

SQL> delete from employee where deptid=(select deptid from department where deptname=’apprentice’;
1 row deleted

SQL> select * from employee;

EMPID DEPTID EMPNAME EMPSALARY BONUS


-------- ------------ ------------------ -------------- ---------------
1000 10 AAA 50000 2500
1001 20 BBB 60000 3000
1002 30 CCC 92000 4600
1004 20 EEE 40000 2000

You might also like