You are on page 1of 14

CSIPLEARNINGHUB

INFORMATICS PRACTICES
PRACTICAL FILE
CLASS 12
2021-2022

1
CSIPLEARNINGHUB

INDEX
S. NO QUERY DATE SIGN
1 Write SQL query to create the table Employee
2 Write SQL query to insert any four records in the
Employee table.
3 Write SQL query to display all the records of all
Female Employees.
4 Write SQL query to display total salary of all the
Employees.
5 Write SQL query to display the average salary of
Employees.
6 Write SQL query to display the details of
Employees with salary more than 40000.
7 Write SQL query to display the total number of
male Employees in the table.
8 Write SQL query to display the maximum and
minimum Salary of Employees
9. Write SQL query to display the detail of Employee
who joined in year 2015.
10. Write SQL query to display name of employees in
upper case who joined on “Wednesday”.

11. Write SQL query to display first 4 alphabets of


Employee Name and last 3 characters of
Department of all Employees.
12. Write SQL query to display the salary Department
wise.

2
CSIPLEARNINGHUB

QUERY - 1

Create the following table: Employee

Field Name Datatype Constraint


Empid Integer Primary Key
Name Varchar (20) Not Null
Department Varchar (20) Not Null
Salary Integer
Gender Varchar (1)
DOJ Date

SOLUTION
Create table Employee
( Empid Integer Primary
Key, Name Varchar(20) Not
Null,
Department Varchar(20) NOT NULL,
Salary Integer,
Gender Varchar(1)
);

3
CSIPLEARNINGHUB

QUERY - 2

Insert the following records in the table created above:


Empid Name Department Salary Gender DOJ
1001 Aman Sales 40000 M 2010-11-21
1002 Suman Accounting 35000 F 2009-09-25
1003 Ravi Sales 45000 M 2015-05-02
1004 Sakshi Accounting 35000 F 2016-06-15

SOLUTION

INSERT INTO EMPLOYEE VALUES (1001, 'Aman', 'Sales ',40000,'M', '2010-11-21');

INSERT INTO EMPLOYEE VALUES (1002, 'Suman', 'Accounting', 35000, 'F', '2009-09-25');

INSERT INTO EMPLOYEE VALUES (1003, 'Ravi', 'Sales', 45000, 'M', '2015-05-02');
INSERT INTO EMPLOYEE VALUES (1004, 'Sakshi', 'Accounting', 35000, 'F', '2016-06-15');

NOTE: After inserting record table will look like

Empid Name Department Salary Gender DOJ


1001 Aman Sales 40000 M 2010-11-21
1002 Suman Accounting 35000 F 2009-09-25
1003 Ravi Sales 45000 M 2015-05-02

1004 Sakshi Accounting 35000 F 2016-06-15

4
CSIPLEARNINGHUB

QUERY - 3

Display all the records of Female Employees.

SOLUTION

Select * from Employee where Gender = ‘F’;

Output:
Empid Name Department Salary Gender
2 Suman Accounting 35000 F
4 Sakshi Accounting 35000 F

5
CSIPLEARNINGHUB

QUERY - 4

Display total salary of all the Employees.

SOLUTION

Select sum(Salary) from Employee;

Output:
sum(Salary)
155000

6
CSIPLEARNINGHUB

QUERY - 5

Display the average salary of Employees.

SOLUTION

Select avg(Salary) from Employee;

Output:
avg(Salary)
38750.00

7
CSIPLEARNINGHUB

QUERY - 6

Display the maximum and minimum Salary of


Employees

SOLUTION

Select max(Salary), min(Salary) from Employee;


Output:

max(Salary) min(Salary)
45000 35000

8
CSIPLEARNINGHUB

QUERY - 7

Display total number of male Employees.

SOLUTION

Select count(*) from Employee where Gender = 'M';


Output:

count(*)
2

9
CSIPLEARNINGHUB

QUERY - 8

Display the average salary of Employees.

SOLUTION

Select avg(Salary) from Employee;

Output:
avg(Salary)
38750.00

10
CSIPLEARNINGHUB

QUERY - 9

Display the detail of Employees who joined in year 2015.

SOLUTION

Select * from Employee where year (DOJ)=2015;


Output:
Empid Name Department Salary Gender DOJ
3 Ravi Sales 45000 M 2015-05-02

11
CSIPLEARNINGHUB

QUERY - 10

Write SQL query to display name of employees in upper


case who joined on “Wednesday”.

SOLUTION

Select upper(Name) from EMPLOYEE where


dayname(DOJ) = "Wednesday";
Output:

upper(Name)
SAKSHI

12
CSIPLEARNINGHUB

QUERY - 11

Write SQL query to display first 4 characters of


Employee Name and last 3 characters of Department of
all Employees.

SOLUTION

Select left(Name,4), right(Department,3) from


Employee;

Output:
left(Name,4) right(Department,3)
Aman les
Suma ing
Ravi les
Saks ing

13
CSIPLEARNINGHUB

QUERY - 12

Write SQL query to display the salary Department wise.

SOLUTION

Select sum(Salary), Department from Employee group


by Department;

Output:
sum(Salary) Department
85000 Sales
70000 Accounting

14

You might also like