Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

EX NO: 05

DATE : 15-03-2021

SQL QUERIES - VENDORS DATABASE

AIM:

Create table Vendors as follows:

Ven_id Ven_nam Contact Street City Salary Dept_id


e
1 Ratna 9044670000 Rajiv Chowk Delhi 30000 A01
2 Anjali 9839780000 Vijay Nagar Kanpur 21000 A01

3 Rahul 9532890000 Model Delhi 35000 B02


Town
4 Ankit 7522900000 Rajajipuram Luckno 24500 C03
w
5 Sumit 7271000000 Ramadevi Kanpur 26000 B02

6 Kapil 7890120000 Mall Road Knpur 27000 C03

7 Abhinav 9984256311 ---- Luckno 25000 C03


w
8 Ankur 9865237411 Akbar Road Delhi 20700 B03

Set Ven_id as primary key

Ven_name and contact can’t have null values.

Write the SQL Queries for the following requirements

Create table and insert 10 sample rows

Add 2 more columns DOB,mailid after the table creation

Find the dept_id and the total number of vendors in individual departments.

Find the minimum and maximum salary paid to individual vendors of individual
departments.

Find the average salary of all the departments having a minimum salary paid at
least 25000.
Find the total number of vendors working in individual departments having a
salary of at least 21000. Consider only those vendors whose street is available
to the organization.

Find the maximum salary of all the departments having more than two
vendors.

Find the average salary of all the departments having more than two vendors.

Retrieve sum of salaries of all vendors working in the department having dept
id=A03.

Retrieve a number of vendors living in each city.

Display the total no. of vendors in each department having a salary of more
than 26000.

Display the total salary spent on each city.

List the cities and the number of vendors in each city. The result should be in
the descending order of the number of vendors.

Write a SQL statement to find the highest salary of an individual department,


for only those vendors whose ID is within the range 03 and 07.

Write a SQL statement to display vendor details (ID and salary) who’s IDs are
within the range 02 and 07 and the highest salary is more than 1000.

PROCEDURE:

create table vendors(Ven_id INT primary key,Ven_name


VARCHAR(20),Contact INT,Street VARCHAR(50),City
VARCHAR(30),Salary INT,Dept_id VARCHAR(50));

insert into vendors values(01,"Ratna",9022130564,"Rajiv


Chowk","Delhi",30000,"A01");

insert into vendors values(02,"Anjali",9874563210,"Vijay


Nagar","Kanpur",21000,"A01");
insert into vendors values(03,"Rahul",8974663210,"Model
Town","Delhi",35000,"B02");

insert into vendors values(04,"Ankit",6541239870,"Rajiji


Puram","Lucknow",24500,"C03");

insert into vendors values(05,"Sumith",9784365120,"Rama


Jayam","Kanpur",26000,"B02");

insert into vendors values(06,"Kapil",7896541032,"Mall


Road","Kanpur",27000,"C03");

insert into vendors values(07,"Abinav",6541239807,"


","Lucknow",25000,"C03");

insert into vendors values(08,"Ankur",8963214710,"Akbar


Road","Delhi",20700,"B02");

insert into vendors values(09,"Sri",9632587401,"Gandhi


Nagar","Chennai",25200,"D04");

insert into vendors values(10,"Kiran",6541239807,"Ashok


Nagar","Delhi",27400,"D04");

alter table vendors add DOB VARCHAR(10);

alter table vendors add mailid VARCHAR(50);

insert into vendors(DOB,mailid) values ('12-09-1995','abc@gmail.com');

insert into vendors(DOB,mailid) values ('03-11-1999','def@gmail.com');

insert into vendors(DOB,mailid) values ('18-01-2000','qwe@gmail.com');

insert into vendors(DOB,mailid) values ('30-06-1995','dfg@gmail.com');

insert into vendors(DOB,mailid) values ('12-12-1999','fgh@gmail.com');

insert into vendors(DOB,mailid) values ('05-03-1999','vdxa@gmail.com');

insert into vendors(DOB,mailid) values ('06-04-1997','ads@gmail.com');

insert into vendors(DOB,mailid) values ('02-02-1996','ppd@gmail.com');


insert into vendors(DOB,mailid) values ('10-01-1998','awz@gmail.com');

insert into vendors(DOB,mailid) values ('23-12-1993','qws@gmail.com');

select Dept_id,COUNT(*)from vendors GROUP BY Dept_id;

select Dept_id,min(Salary),max(Salary) from vendors GROUP BY Dept_id;

select Dept_id,avg(Salary) from vendors GROUP BY Dept_id having


min(Salary)>=25000;

select Dept_id, COUNT(*) from vendors GROUP BY Dept_id having


Salary>=21000 and Street is not null;

select Dept_id, max(Salary),COUNT(*)from vendors GROUP BY Dept_id


having COUNT(Dept_id)>=2;
select Dept_id, avg(Salary),COUNT(*)from vendors GROUP BY Dept_id
having COUNT(Dept_id)>=2;

select Dept_id,sum(Salary) from vendors GROUP BY Dept_id having


Dept_id='C03';

select City,COUNT(*) from vendors GROUP by City;

select Dept_id,COUNT(Dept_id) from vendors where Salary>26000 GROUP


by Dept_id;

select City,sum(Salary) from vendors GROUP by city;


select city,COUNT(*) from vendors GROUP BY Dept_id order by
COUNT(city) desc;

select Dept_id,max(Salary) from vendors GROUP by Dept_id having Dept_id


BETWEEN 'C03' and 'C07';

select Dept_id,max(Salary) from vendors GROUP by Dept_id having Dept_id


BETWEEN 'C03' and 'C07' and max(Salary)>1000;

R.SNEKHA, IT-D

You might also like