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

SQL Prac 4

The document outlines SQL commands for creating and managing a database named OFFICE, specifically a table called Company with employee details. It includes commands for inserting data, querying employee information based on salary and name conditions, and modifying the table structure by adding new columns. Additionally, it demonstrates the use of string functions and aggregate functions to analyze employee data.

Uploaded by

FYCS34 HARSH
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)
9 views

SQL Prac 4

The document outlines SQL commands for creating and managing a database named OFFICE, specifically a table called Company with employee details. It includes commands for inserting data, querying employee information based on salary and name conditions, and modifying the table structure by adding new columns. Additionally, it demonstrates the use of string functions and aggregate functions to analyze employee data.

Uploaded by

FYCS34 HARSH
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/ 3

Practical 4 - Use of String function, Relational Operators, Arithmetic Operators &

Constraints in SQL

Create the following table Company in Database Office.

Branch no. Name of the employee Employee id salary Manager under work

01 Suresh E1 25000 M1

02 Ramesh E2 22000 M1

03 Dinesh E3 21000 M2

04 Kalpesh E4 20000 M1

05 Alpesh E5 21600 M3

06 Adesh E6 26000 M5

07 Rajesh E7 27000 M3

08 Zareen E8 30000 M4

09 Seema E9 20000 M2

10 Esha E10 27500 M2

Create a database OFFICE.


create database OFFICE;
Write a command to use the database OFFICE.
use OFFICE;
Create a table Company.
create table Company (branch_no smallint ,
emply_name varchar(20),EMP_id varchar(20), salary smallint, manager_id varchar(20));
Describe table Company.
describe Company;
Insert the values in table Company.
insert into Company values(01, 'Suresh', 'E1', 25000,'M1'),(02, 'Ramesh','E2', 22000,'M1'),(03,
'Dinesh', 'E3', 21000,'M2'),(04, 'Kalpesh','E4',20000,'M1'),(05, 'Alpesh','E5',21600,'M3'),(06,
'Aadesh', 'E6',26000,'M5'),(07, 'Rajesh','E7',27000,'M3'),(08, 'ZAREEN','E8',30000,'M4'),(09,
'SEEMA', 'E9',20000,'M2'),(10, 'Esha','E10',27500,'M2');
Display all the employee details in Company.
select *from Company;
Count total number of employees having a salary.
Select count(salary) from company;
Find the most maximum salary paid by the company.
select max(salary) from Company;
Find the most minimum salary paid by the company.
select min(salary) from Company;
Find the average salary paid by the company.
select avg(salary) from Company;
Find the total salary paid by the company.
select sum(salary) from Company;
Alternatively, one can find count, max, min, average and total salary in a single query.
Select count(salary), max(salary), min(salary), avg(salary), sum(salary) from company;
Find the details of the employee who received a salary less than 21000.
select *from company where salary <=21000;
Find the details of the employee who received a salary more than 21000.
select *from company where salary >=21000;
Find the details of the employee whose salary is 30000.
select *from company where salary=30000;
Find the details of the employees whose salary is not 30000.
select *from company where salary !=30000;

Notice here that using query select max(salary) from Company; you get output 30000 and
using the query select *from company where salary=30000; you get detailed output.

In order to get the details of employees having maximum salary enter the following
select *from company where salary=(select max(salary) from Company);
In order to get the details of employees having minimum salary enter the following
select *from company where salary=(select min(salary) from Company);

Find the details of employees whose name starts with A.


select branch_no,emply_name,EMP_id,salary from company where emply_name like 'a%';
Find the details of employees whose name does not start with A.
select branch_no,emply_name,EMP_id,salary from company where emply_name not like 'a%';
Find the details of the employee E3 and E7.
select branch_no,emply_name,EMP_id,salary from company where EMP_id in('e3' ,'e7');
Find the details of employees who receive salaries between 21000 and 23000.
select branch_no,emply_name,EMP_id,salary from company where salary between 21000 and
23000;
Add column of DA, HRA and Gross_Income in the table company
alter table company add(DA bigint);
alter table company add(HRA bigint);
alter table company add(Gross_Income bigint);
Set the records in the column of DA,HRA and Gross_Income
Update company set DA=(Select 20*salary/100);
Update company set HRA=(select 10*salary/100);
Update company set Gross_income=(select salary+DA+HRA);
Select * from company;
Show the names of the employees in upper case.
select upper(emply_name) from company;
Show the names of the employees in lower case.
select lower(emply_name) from company;
Find the length of characters in the column emply_name
Select length(emply_name) from company;

You might also like