0% found this document useful (0 votes)
74 views6 pages

Name: Siva 19BCE1582 Ex. 2 DML

The document details creating an "Employee" table with attributes like EmpId, Name, Department, etc. and inserting over 10 records. It then provides several queries: 1) List employees in the "Testing" department. 2) Calculate the average salary for the "HR" department. 3) Count employees in the "Development" department with grade "B". 4) Find the total, minimum, and total salaries including bonuses for all employees and departments.

Uploaded by

siva an
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views6 pages

Name: Siva 19BCE1582 Ex. 2 DML

The document details creating an "Employee" table with attributes like EmpId, Name, Department, etc. and inserting over 10 records. It then provides several queries: 1) List employees in the "Testing" department. 2) Calculate the average salary for the "HR" department. 3) Count employees in the "Development" department with grade "B". 4) Find the total, minimum, and total salaries including bonuses for all employees and departments.

Uploaded by

siva an
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NAME: SIVA 19BCE1582

Ex. 2 DML
Create table “Employee” and insert atleast 10-20 records. Set Empid as primary key.
Empid :
Attribute Description/Data Type/Constraint
EmpId Employee’s unique ID. Max. 4 characters should be numeric (Primary Key)
Name Employee’s first name. Max. 15 characters. (Not Null)
Department Max. 15 characters (Not Null) (Only HR, Testing, Development and Accounts)
Grade Max. 3 characters (Only Grades A , B ,C allowed)
Basic Pay Decimal point number length 10 with precision 2
Salary Pay Decimal point number length 10 with precision 2
Bonus Points Decimal point number length 5 with precision 2
HireDate Date on which employee was hired. Date data type.

create table Employee(EmpId decimal(4,0) primary key,Name varchar(15) not null,Department


varchar(15) not null,Grade char check(Grade='a' or Grade = 'b' or Grade='c'),Basicpay
decimal(10,2),Salarypay decimal(10,2),Bonuspoints decimal(5,2),Hiredate date);
desc Employee;
INSERTING VALUE:
INSERT INTO
Employee(EmpId,Name,Department,Grade,Basicpay,Salarypay,Bonuspoints,Hiredate)
WITH names AS (
SELECT 1582,'siva','Testing','a',10000,5000,500,TO_DATE('2002-03-12','YYYY-MMDD') FROM dual
UNION ALL
SELECT 1459,'damian','Development','b',4500,5015,500,TO_DATE('2002-03-12','YYYY-MMDD')
FROM dual UNION ALL
SELECT 1678,'kevin','Testing','b',6500,35000,100,TO_DATE('2002-03-12','YYYY-MMDD') FROM
dual UNION ALL
SELECT 1009,'Dinesh','Development','c',1000,5000,500,TO_DATE('2002-03-12','YYYY-MMDD')
FROM dual UNION ALL
SELECT 1690,'magesh','Testing','a',9500,300,600,TO_DATE('2002-03-12','YYYY-MMDD') FROM
dual UNION ALL
SELECT 1554,'bharath','Development','c',9500,2340,400,TO_DATE('2002-03-12','YYYY-MMDD')
FROM dual UNION ALL
SELECT 1500,'sur','HR','c',9000,2340,450,TO_DATE('2002-03-12','YYYY-MMDD') FROM dual
UNION ALL
SELECT 1600,'Drake','HR','b',4000,5015,590,TO_DATE('2002-03-12','YYYY-MMDD') FROM dual
UNION ALL
SELECT 1442,'paru','Testing','b',6000,2500,400,TO_DATE('2002-03-12','YYYY-MMDD') FROM dual
)
SELECT * FROM names
select * from Employee

⦁ List the employee details in “ Testing“ department.

select * From Employee where Department='Testing';

⦁ Calculate the average salary of all employees in “HR” department


SELECT AVG(Salarypay)
FROM Employee
WHERE Department='HR';

⦁ Count number of employees in “ Developement” department and with “B” grade.


SELECT COUNT(Department)
FROM Employee
WHERE Grade='b' and Department='Development';

⦁ Calculate the total salary of all employees


SELECT SUM(Salarypay)
FROM Employee;

⦁ Find the Lowest salary in “HR” department.


SELECT MIN(Salarypay)
FROM Employee
WHERE Department='HR';

⦁ List the employee details who got the minimum bonus points
select * from Employee
where Bonuspoints=(select min(Bonuspoints) from Employee);

⦁ List all the employee id and name with their bonus amount ( bonus amount will be
calculated by multiplying bonus point with the basic salary)
ALTER TABLE Employee ADD Bonusamount Decimal(10,2);
UPDATE Employee SET Bonusamount = Bonuspoints*Basicpay/100;
select EmpId,name,Bonusamount from Employee;

⦁ Calculate the total salary of all employees ( total salary = salary + bonus amount)
ALTER TABLE Employee ADD Totalsalary Decimal(10,2);

UPDATE Employee SET Totalsalary =Bonusamount+Salarypay;

select * from Employee;

⦁ How many employee earn salary more than 45000


select * from Employee
where Totalsalary>45000;

⦁ How many employee earn salary in the range between 30k and 40k
select * from Employee
where Totalsalary>30000 and Totalsalary<45000;

⦁ Sort the relation with respect to the Salary in descending order.


SELECT *
FROM Employee
ORDER BY Totalsalary DESC;

⦁ List the departments in which the average salary of the employees is greater than 40,000
SELECT Department from Employee WHERE Salarypay > (SELECT AVG(Salarypay) FROM
Employee);

⦁ Display the department name starts with ‘H’


SELECT * FROM Employee WHERE Department LIKE 'H%'

You might also like