0% found this document useful (0 votes)
21 views

Python Practicle 9

The document discusses performing SQL queries on an EMP table: adding a column, updating values, finding employees above average salary in a department, listing salaries in descending order, and ordering departments and employees. Oracle 10g is used to create tables, insert data, and run the queries.

Uploaded by

satvik john
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Python Practicle 9

The document discusses performing SQL queries on an EMP table: adding a column, updating values, finding employees above average salary in a department, listing salaries in descending order, and ordering departments and employees. Oracle 10g is used to create tables, insert data, and run the queries.

Uploaded by

satvik john
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PRACTICAL/OBJECTIVE/PROBLEM DEFINITION-9:

Consider EMP table and perform the following using SQL commands :

(i) Add a new column called total sal to the table.

(ii) Update the total sal column with sal+commission.

(iii) Find the employees having salary greater than average salary of the employees working in dept 10.

(iv) List employee name and yearly salary and arrange the output on the basis of yearly salary in

descending order.

(v) Retrieve the names of departments in ascending order and their employees in descending order.

THEORY:-
We are going to use Oracle 10g to create these relational database tables :

1. First create a table-Employee and add constraints if necessary


2. Then insert values in the table
3. We have shown each step with the result below
4. We have performed the queries according to the problems

SOFTWARE USED:-

Oracle 10G, SQL, Window 7 professional.

PROGRAM/QUERIES AND RESULT:-


Queries for table creation and data insertion are shown below:

1. Employee Table :

create table employee


(
employee_number number(10) primary key,
employee_name varchar2(15),
dept_number number(10),
dept_name varchar2(25),
salary number(20) not null,
commission number(20)
);
DESC Employee;

Data Insertion:-

begin
insert into employee
values(101,'satvik',08,'Accounts',9000,2000);

insert into employee


values(102,'harshit',04,'Marketing',18000,9000);

insert into employee


values(103,'nikhil',09,'Sales',12000,1000);

insert into employee


values(04,'akshay',04,'Marketing',15000,3500);

insert into employee


values(105,'Sameer',06,'Management',7000,2000);
end

select * from Employee;


Now, perform the following operations using SQL commands :

(i) Add a new column called total salary to the table.

alter table employee add total_salary number(20);

(ii) Update the total sal column with sal+commission.

update employee set total_salary= salary+commission;


(iii) Find the employees having salary greater than average salary of the employees working indept 10.

selectemployee_name from employee where salary>(select avg(salary) from employee where


dept_number=04);

(iv) List employee name and yearly salary and arrange the output on the basis of yearly salary
indescending order.

select employee_name, 12*salary as "Yearly Salary" from employee order by "Yearly Salary" desc;

(v) Retrieve the names of departments in ascending order and their employees in descending
order.

select dept_name, employee_name from employee order by dept_name, employee_name desc;

You might also like