You are on page 1of 25

ALIGARH COLLEGE OF ENGINEERING AND TECHNOLOGY,ALIGARH

(Approved By AICTE New Delhi, Affiliated to AKTU Lucknow)

PRACTICAL FILE
Submitted in partial fulfillment for the award of
BACHELOR OF TECHNOLOGY
(CSE), 3rd year
Submitted by
RUPESH VARSHNEY
Roll No:- 2001090100045

Submitted To
Mr. Kapil Arora
(Database Management Systems Lab: KCS-551)
[Session: 2022-2023]
INDEX
S.NO EXPERIMENTS SIGNATURE

1. Perform SQL Query on Employees Table

2. Perform SQL Query on Employees,


Department & Allowance Table

3. Perform SQL Query on Employees,


Department & Allowance Table

4. Perform SQL Query on Programmer , Software


& Studies Table

5. Perform SQL Query on Programmer , Software


& Studies Table

Name:- Rupesh Varshney

Practical Name:- Database Management Systems Lab

Practical Code:- KCS-551

Branch/Year:- CSE 3rd Year

Semester:- 5th

Class Roll No:- B-05

AKTU Roll No:- 2001090100045


PRACTICAL ASSIGNMENT-1
create table eemployee

emp_no number(5) not NULL,

emp_name VARCHAR(30),

designation char(10),

doj date,

salary NUMERIC(9,2),

address VARCHAR(30),

dept_name CHAR(30)

);

insert into eemployee(emp_no,emp_name,designation,doj,salary,address,dept_name)

VALUES('1001','amit','officer','21-dec-1995','1000','mathura','marketing'),

('1002','sumit','clerk','14-may-1982','500','delhi','accounts'),

('1003','raj','manager','23-dec-1984','3500','bombay','sales'),

('1004','james','analyst','22-jul-1990','5000','mathura','software'),

('1005','amit','analyst','22-jul-1990','4900','delhi','production'),

('1006','jones','clerk','16-apr-1986','950','delhi','production');

SELECT * FROM eemployee;

SQL QUERIES:
1. List the Emp name, doj from employee table.

SELECT emp_name,doj FROM eemployee;


2. List the names of Employee who is getting 1000 Rs.

SELECT emp_name FROM eemployee WHERE salary=1000;

3. List the name of emp who belong to Mathura and depart name is Marketing.

SELECT emp_name FROM eemployee WHERE address='mathura' AND dept_name='marketing';

4. List the average salary of Amit.

SELECT avg(salary) FROM eemployee WHERE emp_name='amit';

5. List the name of the emp who are getting their salary between 800 and 2500.

SELECT emp_name FROM eemployee WHERE salary BETWEEN 800 AND 2500;

6. Find the experince of all the employees.

SELECT emp_name,months_between(sysdate,DOJ)/12 as experience FROM eemployee;

7. List the employees who are earning more than 1200 but less than 4000.

SELECT emp_name FROM eemployee WHERE salary>1200 and salary<4000;


8. List the employees who have joined after 1-Jan-84 in the order of the joining date.

SELECT emp_name FROM eemployee WHERE doj>('01-jan-1984');

9. List the employees who are located at Mathura.

SELECT emp_name FROM eemployee WHERE address='mathura';

10. List the employees who are in sales dept.

SELECT emp_name FROM eemployee WHERE dept_name='sales';

11. List the departments that are located in Delhi.


SELECT dept_name FROM eemployee WHERE address='delhi';

12. List the employees who are not working in Delhi.

SELECT emp_name FROM eemployee WHERE address not in ('delhi');


13. Find out how many employees are there in organization.

SELECT dept_name,COUNT(*) FROM eemployee GROUP BY dept_name;

14. Find out the total salary of Amit.

SELECT sum(salary) FROM eemployee WHERE emp_name='amit';

15. Find out how many employees are working in the sales department.

select COUNT(dept_name) from eemployee WHERE dept_name='sales';


PRACTICAL ASSIGNMENT-2

create table employee

emp_no NUMBER NOT NULL,

emp_name VARCHAR2(20),

designation CHAR(10),

doj DATE,

salary NUMBER(10),

dept_no NUMBER(10)

);

create table department

dept_no NUMBER(10),

dept_name CHAR(30),

dept_loc CHAR(30)

);

create table allowance

designation CHAR(10),

sp_allowance NUMBER(9),

conveyance NUMBER(9)

);

insert into employee(emp_no,emp_name,designation,doj,salary,dept_no)

VALUES('1001','ROBERT','OFFICER','21-DEC-85','1000','10'),

('1002','ALLAN','CLERK','15-MAY-82','500','10'),

('1003','MARTIN','MANAGER','23-DEC-84','3500','20'),

('1004','JAMES','ANALYST','22-JUL-90','5000','30'),

('1005','JOHN','ANALYST','22-JUN-90','4900','30');

insert into department(dept_no,dept_name,dept_loc)

VALUES('10','marketing','london'),
('20','accounts','america'),

('30','sales',' newyork'),

('40','software','boston'),

('50','production','boston');

insert into allowance(designation,sp_allowance,conveyance)

VALUES('manager','1000','500'),

('officer','800','400'),

('analyst','1200','500'),

('clerk','500','300');

SELECT * FROM employee;

SELECT * FROM department;

SELECT * FROM department;


SQL QUERIES:
1. List the employee belonging to department 20.

select * from employee where dept_no=20;

2. List the employee who are earning more than 1200 but less than 4000.

select * from employee where salary between 1200 AND 4000;

3. List the employee who have joined after 1-Jan-84 in order of joining date.

select emp_name from employee where doj>'01-jan-84';

4. List the employee who are either an Officer or Manager position.

select * from employee where designation='OFFICER' OR designation='MANAGER';

5. List the employee who are located in ‘NEWYORK’.

select * from employee where dept_no=(select dept_no from department where dept_loc=' newyork');

6. List the employee who are in Sales Department.


SELECT emp_name from employee where dept_no=(select dept_no from department where
dept_name='sales');
7. List the departments that do not have an employee.
select * from department where dept_no not in (select dept_no from employee);

8. List the employee who are earning more than Robert.

select * from employee where salary > (select salary from employee where emp_name='ROBERT');

9. Find out how many employees are there in organization.


select d.dept_name,count(d.dept_no) as Total Employee from employee e,department d where
e.dept_no=d.dept_no group by d.dept_name;

10. Find out the total salary paid to the employee.


select sum(salary) from employee;

11. Find out how many employee are working in Sales department.

select * from employee where dept_no=(select dept_no from department where dept_name='sales');

12. What is the average salary paid to the employees?


select AVG(salary) from employee;

13. What is the minimum salary paid in DEPT 30?


select MIN(salary) from employee where dept_no=30;
14. Display names and grades of employee based on their designation

DESIGNATION GRADE

Manager A

Officer B

Analyst C

Clerk D

ALTER TABLE employee

ADD grade varchar(10);

update employee set grade='A' where designation ='MANAGER';

update employee set grade='B' where designation ='OFFICER';

update employee set grade='C' where designation ='ANALYST';

update employee set grade='D' where designation ='CLERK';

SELECT emp_name , grade FROM employee;

15. Display the employees names and doj,joining date should be displayed in the following format:26 JAN,NINTEEN
NINETY-EIGHT.

select emp_name,to_char(doj,'dd month , year') from employee;


PRACTICAL ASSIGNMENT-3
SQL QUERIES:
1. Find out how long an employee has worked in the organization in terms of number of Days, Months
&Year.

Select emp_name,
convert(varchar(3),DATEDIFF(MONTH,DOJ,GETDATE())/12)+'years'"YEARS",
convert(varchar(2),DATEDIFF(MONTH,DOJ,GETDATE())%12)+'month'"MONTHS",
convert(int,DATEDIFF(MONTH,DOJ,GETDATE())*30.5)"DATE"
from employee;

2. Display the total salaries department wise.

select d.dept_name , sum(e.salary) as Total_Salary


from employee e,department d
where e.dept_no=d.dept_no
group by d.dept_name;

3. Display the maximum salaries in each department along with the name of department. The column
heading should be like this: Dept_Name Max(Sum) Hint : Use both the tables – Employee &
Department.

select d.dept_name,max(salary) as MAX_SALARY from employee e,department d where


e.dept_no=d.dept_no group by d.dept_name;

4. Display the total salary( Salary+Sp_allowance_Conveyance) of each employee in the order of total
salary.

select emp_name,sum(e.salary+a.sp_allowance+a.conveyance)AS Total_Salary


from employee e,allowance a
where e.designation=a.designation
group by emp_name;

5. List the no. of Employees along with their department numbers in each department.

select dept_no,count(emp_name) from employee group by dept_no;


6. List the department wise total salary.

select d.dept_name , sum(e.salary) as Total_Salary


from employee e,department d
where e.dept_no=d.dept_no
group by d.dept_name;

7. List the number of employees in each designation in the descending order.

select designation,COUNT(*) from employee group by designation;

8. List the total salary, maximum and minimum along with the average salary of each employee
designation wise.

select designation,max(salary) as MAX_SALARY,sum(salary) as TOTAL_SALARY ,min(salary) as


MIN_SALARY,avg(salary)as AVERAGE_SALARY from employee group by designation;

9. List the total salary, maximum and minimum along with the average salary of each employee
designation wise for department no.30.

select designation,max(salary)"MAX SALARY",sum(salary)"TOTAL SALARY",min(salary)"MIN


SALARY",avg(salary)"AVERAGE SALARY" from employee where dept_no=30 group by designation;
10. List the total salary, maximum and minimum along with the average salary of each employee
designation wise for department no.30 and display only these rows that have their average salary
greater than 1000.

select designation,max(salary)"MAX SALARY",sum(salary)"TOTAL SALARY",min(salary)"MIN


SALARY",avg(salary)"AVERAGE SALARY" from employee where dept_no=30 group by designation;

11. List the total salary of the employees for each designation department wise.

select e.designation,d.dept_name,sum(e.salary)"Total Salary" from employee e,department d where


e.dept_no=d.dept_no group by e.designation,d.dept_name;

12. List the employee details such as his Employee no., Name, Date of Joining, Basic Salary and
Designation of department=’Marketing’.
select emp_no,emp_name,doj,salary,designation from employee where dept_no in (select dept_no from
department where dept_name='marketing');

13. List the employee details such as his Employee no., Name, Date of Joining, Basic Salary and
Designation for the employee working in location = ‘AMERICA’.

select emp_no,emp_name,doj,salary,designation from employee where dept_no in (select dept_no from


department where dept_loc='america');

14. List the departments where there are no employee functioning.

select * from department where dept_no not in (select dept_no from employee);
PRACTICAL ASSIGNMENT-4

CREATE TABLE PROGRAMMER

NAME VARCHAR2(8),

DOB DATE,

DOJ DATE,

SEX VARCHAR2(1),

PROF1 VARCHAR2(8),

PROF2 VARCHAR2(8),

SALARY NUMBER(8)

);

INSERT INTO PROGRAMMER VALUES('RAMKUMRA','21-APR-1966','21-APR-


2000','M','PASCAL','BASIC',3200),

('ALTAF','02-JUL-1980','13-NOV-2001','M','CLIPPER','COBOL',2800),

('JAGDESH','05-OCT-1987','04-OCT-1999','M','ORACLE','JAVA',4100),

('JULIANA','31-JAN-1986','21-APR-1998','F','COBOL','DBASE',3000),

('KAMALA','30-OCT-1992','02-JUN-1999','F','C','DBASE',2900),

('MARY','24-JUN-1989','01-FEB-2004','F','C','ORACLE',4500),

('NELSON','11-SEP-1990','11-OCT-2003','M','COBOL','DBASE',2500),

('PATRICI','16-NOV-1991','21-APR-2002','M','PASCAL','CLIPPER',2800),

('QADIR','31-AUG-1987','21-APR-2006','M','ASSEMBLY','C',3000),

('RAMESH','03-MAY-1983','28-FEB-2005','M','PASCAL','DBASE',3200),

('REBECCA','01-JAN-1987','01-DEC-1990','F','BASIC','COBOL',2500),

('REMITHA','19-APR-1988','20-APR-1993','F','C','ASSEMBLY',3600),

('REVATHI','02-DEC-1991','02-JAN-1992','F','PASCAL','BASIC',3700),

('VIJAYA','11-DEC-1992','02-MAY-1992','F','FOXPRO','C',3500);

CREATE TABLE SOFTWARE(

NAME VARCHAR2(8),

TITLE VARCHAR2(20),

DEV_IN VARCHAR2(8),

SCOST NUMBER(7,2),

DCOST NUMBER(5),

SOLD NUMBER(3));
INSERT INTO SOFTWARE

VALUES('ANAND','PARACHUTES','BASIC',399.95,6000,43),

('ANAND','VIDEO TITLING PACK','PASCAL',7500.00,16000,9),

('JAGADESH','SERIAL LINK UTILITY','JAVA',800.00,7500,10),

('JAGADESH','SHARES MANAGEMENT','ORACLE',3000.00,12000,14),

('JULIANA','INVENTORY CONTROL','COBOL',3000.00,3500,0),

('KAMAL','PAYROLL PACKAGE','DBASE',9000.00,20000,7),

('MARY','FINANCIAL ACC S/W','ORACLE',18000.00,85000,4),

('MARY','CODE GENERATOR','C',4500.00,20000,23),

('MARY','READ ME','C',300.00,1200,84),

('PATRICK','GRAPHIC EDITOR','PASCAL',750.00,5000,11),

('QADIR','BOMBS AWAY','ASSEMBLY',499.80,530,114),

('QADIR','VACCINES','C',1900.00,3400,21),

('RAMESH','HOTEL MANAGEMENT','DBASE',12000.00,35000,4),

('RAMESH','DEAD LEE','PASCAL',99.95,4500,73),

('REMITHA','PC UTILITIES','C',725.00,500,51),

('REMITHA','TSR HELP PACKAGE','ASSEMBLY',2500.00,6000,6),

('REVATHI','HOTEL MANAGEMENT','PASCAL',1100.00,75000,2),

('REVATHI','QUIZ MASSTER','BASIC',3200.00,2100,15),

('VIJAYA','ISK EDITOR','C',900.00,700,6);

CREATE TABLE STUDIES

NAME VARCHAR2(8),

SPLACE VARCHAR2(9),

COURSE VARCHAR2(5),

CCOST NUMBER(5)

);

INSERT INTO STUDIES

VALUES('ANAND','SABHARI','PGDCA',4500),

('ALTAF','CCIT','DCA',7200),
('JAGADESH','SSIL','DCA',3500),

('JULIANA','BITS','DCA',22000),

('KAMALA','PRAGATHI','DCP',5000),

('MARY','SABHARI','PGDCA',4500),

('NELSON','PRAGATHI','DAP',5200),

('PATRICK','PRAGATHI','DCAP',5200),

('QADIR','APPLE','HDCP',14000),

('RAMESH','SABHARI','PGDCA',4500),

('REBECCA','BRILLANT','DCA',11000),

('REMITHA','BDPS','DCA',6000),

('REVATHI','SABHARI','DAP',5000),

('VIJAYA','BDPS','DCA',48000);

SELECT * FROM PROGRAMMER;


select * from SOFTWARE;

select * from STUDIES;


SQL QUERIES:
1. How many programmers have done the PGDCA course.

SELECT COUNT (NAME) FROM STUDIES WHERE COURSE LIKE 'PGDCA';

2. How much revenue has been earned through sales of packages in C.

SELECT SUM(ABS((SCOST-DCOST))*SOLD) AS REVENUE FROM SOFTWARE WHERE


DEV_IN='C';

3. Display the details of SOFTWARE developed by Ramesh.

SELECT * FROM SOFTWARE WHERE NAME='RAMESH';

4. Display the details of Package who’s sales CROSSED the 20000 .

SELECT * FROM SOFTWARE WHERE (SOLD*SCOST)>20000;

5. Display the details of programmers knowing C.

SELECT * FROM PROGRAMMER WHERE PROF1='C' OR PROF2='C';

6. How many programmers don’t know PASCAL & C.

SELECT COUNT (NAME) AS PROGRAMMERS FROM PROGRAMMER WHERE PROF1 NOT IN


('C','PASCAL')AND PROF2 NOT IN ('C','PASCAL');
7. What are the languages known by the male programmers.

SELECT DISTINCT PROF1 AS LANGUAGES FROM PROGRAMMER WHERE SEX='M'


UNION SELECT DISTINCT PROF2 AS LANGUAGES FROM PROGRAMMER WHERE SEX='M';

8. How many people draw 2000 to 4000.

SELECT NAME FROM PROGRAMMER WHERE SALARY BETWEEN 2000 AND 4000;

9. Display the institute names from the STUDIES table without duplicates.

SELECT DISTINCT SPLACE FROM STUDIES;

10. Display the name of the programmers who’s name starts with ‘A’ and the third character is T.

SELECT NAME FROM PROGRAMMER WHERE NAME LIKE ‘A_T%’;


PRACTICAL ASSIGNMENT-5
SQL QUERIES:
1. Find out the selling cost average for package developed in Oracle.

SELECT AVG(SCOST) FROM SOFTWARE WHERE DEVIN = 'ORACLE';

2. Display the names, ages and experience of all programmers.

SELECT NAME,MONTHS_BETWEEN(SYSDATE,DOB)/12 As AGE,


MONTHS_BETWEEN(SYSDATE,DOJ)/12 as EXPERIENCE FROM PROGRAMMER;

3. Display the name of those who have done PGDCA course.

SELECT NAME FROM STUDIES WHERE COURSE = 'PGDCA';

4. What is the highest number of copies sold by a package?

SELECT MAX(SOLD) FROM SOFTWARE;

5. Display the names & date of birth of all programmers born in April.

SELECT PNAME, DOB FROM PROGRAMMER WHERE DOB LIKE '%APR%';

6. Display the lowest course fee.

SELECT MIN(CCOST) FROM STUDIES;

7. How many programmers have done the DCA course.

SELECT COUNT(*) FROM STUDIES WHERE COURSE = 'DCA';


8. How much revenue has been earned through the sale of packages developed in C.

SELECT SUM(SCOST*SOLD-DCOST) FROM SOFTWARE GROUP BY DEV_IN HAVING DEV_IN =


'C';

9. How many programmers studied at Pragathi.

SELECT * FROM STUDIES WHERE SPLACE = 'PRAGATHI';

10. Find out the number of copies which should be sold in order to recover the development cost of
each package.

SELECT CEIL(DCOST/SCOST) FROM SOFTWARE;

11. What is the price of costliest software developed in DBASE?


SELECT MAX(SCOST) FROM SOFTWARE GROUP BY DEV_IN HAVING DEV_IN = 'DBASE';

12. How many packages were developed in Oracle?


SELECT COUNT(*) FROM SOFTWARE WHERE DEVIN = 'ORACLE';
13. Display the details of packages for which the development cost has been recovered.

SELECT * FROM SOFTWARE WHERE SCOST*SOLD >= DCOST;

14. How many programmers studied at PRAGATHI?

SELECT COUNT(*) FROM STUDIES WHERE SPLACE = 'PRAGATHI';

15. How many programmers paid 10000 to 15000 for the course?

SELECT COUNT(*) FROM STUDIES WHERE CCOST BETWEEN 10000 AND 15000;

16. What is the average course fee?

SELECT AVG(CCOST) FROM STUDIES;

17. How old is the oldest male programmer?


SELECT TRUNC(MAX(MONTHS_BETWEEN(SYSDATE,DOB)/12)) FROM PROGRAMMER WHERE
SEX = 'M';

18. What is the average age of female programmers?


SELECT TRUNC(AVG(MONTHS_BETWEEN(SYSDATE,DOB)/12)) FROM PROGRAMMER WHERE
SEX = 'F';
19. Calculate the experience in years for each programmer & display along with their names in
descending order.
SELECT NAME, TRUNC(MONTHS_BETWEEN(SYSDATE,DOJ)/12) FROM PROGRAMMER ORDER
BY NAME DESC;

20. How many programmers know either C or Pascal?

SELECT * FROM PROGRAMMER WHERE PROF1 IN ('C','PASCAL') OR PROF2 IN ('C','PASCAL');

21. Who are the programmers who celebrate their birthdays during the current month?

SELECT NAME FROM PROGRAMMER WHERE TO_CHAR(DOB,'MON') = TO_CHAR(SYSDATE,'MON');

22. How many female programmers are there?

SELECT COUNT(*) FROM PROGRAMMER WHERE SEX = 'F';

23. What is the average salary?

SELECT AVG(SAL) FROM PROGRAMMER;

24. Display the details of those who don’t know C, C++ or Pascal.

SELECT * FROM PROGRAMMER WHERE PROF1 NOT IN ('C','C++','PASCAL') AND PROF2 NOT IN
('C','C++','PASCAL');
25. Display the costliest package developed by each programmer.

SELECT NAME,TITLE,SCOST FROM SOFTWARE WHERE SCOST IN (SELECT MAX(SCOST)


FROM SOFTWARE GROUP BY NAME);

26. Produce the following output for all the male programmers

( Programmer

Mr. Arvind – has 15 years of experience )

SELECT 'Mr.' || NAME || ' - has ' || TRUNC(MONTHS_BETWEEN(SYSDATE,DOJ)/12) || ' years of experience'
“Programmer” FROM PROGRAMMER WHERE SEX = 'M' UNION SELECT 'Ms.' || NAME || ' - has ' || TRUNC
(MONTHS_BETWEEN (SYSDATE,DOJ)/12) || ' years of experience' “Programmer”

FROM PROGRAMMER WHERE SEX = 'F';

You might also like