0% found this document useful (0 votes)
23 views10 pages

23027119-056 DB Quiz

Uploaded by

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

23027119-056 DB Quiz

Uploaded by

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

QUIZ#1

Course Title:Database System


Course Code:CS-241
Submitted by:
Aliza Waris
(23027119-056)
Semester:BS-5th intake (2nd)
Department of Computer Science

create table SalesRepc


(
sal_rep_id int primary key,
SalRep_name varchar(255),
Office_id int,
title varchar(255),
age int,
hiredate date,
manager int,
quota int,
sales int,
target int,
)
insert into
SalesRepc(sal_rep_id,SalRep_name,office_id,title,age,hiredate,manager
,quota,sales,target)
values
(01,'ali',101,'sales manager',35,'2023-03-14',null,40000,45000,50000),
(02,'hassan',102,'senior sales executive',36,'2024-05-
15',2001,55000,60000,65000),
(03,'shazal',103,'sales executive',23,'2024-05-
08',2002,30000,35000,40000)

select*from SalesRepc

List the name and hire date of anyone with sales over
50000:
SELECT SalRep_name, Hiredate
FROM SalesRepc
WHERE Sales > 50000;
2.Show me the result if I raised each person's quota by
3 percent of their year to date sales:

SELECT SalRep_name, Quota, (Quota + (Sales * 0.03)) AS NewQuota


FROM SalesRepr;

3. List sales people whose sales are not between 80


percent and 120 percent of the target:
SELECT SalRep_name
FROM SalesRepp
WHERE Sales < (Target * 0.8) OR Sales > (Target * 1.2);
create table officeo
(
office_id int primary key,
City varchar(255),
Region char(255),
Target int,
Sales int
)

insert into officeo(office_id,city,Region,Target,Sales)


values
(101,'karachi','sindh',80000,60000),
(102,'lahore','punjab',90000,70000),
(103,'islamabad','federal',55000,50000)
select*from officeo

4.List the offices whose sales fall below 80 percent of


target:

SELECT City, Region


FROM Officeo
WHERE Sales < (Target * 0.8);
create table Customerm
(
Customer_id int primary key,
customer_name varchar(255),
company varchar(255),
creditLimit int,
address varchar(255),
sal_rep_id int,
)

insert into
Customerm(Customer_id,customer_name,company,creditLimit,address
,sal_rep_id)
values
(201,'ali','xyz pvt.ltd',40000,'123 main st karachi',0001),
(202,'hassan','abc ltd',50000,'456 first st lahore',0002),
(203,'hamza','pqr corporation',60000,'789 second st islamabad',0003)
select*from Customerm

List all the customers whose name starts with 'A' or 'a':
SELECT customer_name
FROM Customerm
WHERE customer_name LIKE 'A%' OR customer_name LIKE 'a%';

create table ordersg


(
order_id int primary key,
customer_id int,
product_id int,
qty int,
amount int,
sal_rep_id int,
order_date date
)
insert into
ordersg(order_id,customer_id,product_id,qty,amount,sal_rep_id,order
_date)
values
(1,13,201,4,5000,001,'2024-05-05'),
(2,14,202,5,6000,002,'2024-05-07'),
(3,15,203,6,6500,003,'2024-05-08')
select *from ordersg
create table SalesRepg
(
sal_rep_id int primary key,
SalRep_name varchar(255),
Office_id int,
title varchar(255),
age int,
hiredate date,
manager int,
quota int,
sales int,
target int,
)

insert into
SalesRepg(sal_rep_id,SalRep_name,office_id,title,age,hiredate,manage
r,quota,sales,target)
values
(01,'ali',101,'sales manager',35,'2023-03-14',null,40000,45000,50000),
(02,'hassan',102,'senior sales executive',36,'2024-05-
15',2001,55000,60000,65000),
(03,'shazal',103,'sales executive',23,'2024-05-
08',2002,30000,35000,40000)

select*from SalesRepg

create table Customerg


(
Customer_id int primary key,
customer_name varchar(255),
company varchar(255),
creditLimit int,
address varchar(255),
sal_rep_id int,
)

insert into
Customerg(Customer_id,customer_name,company,creditLimit,address,
sal_rep_id)
values
(201,'ali','xyz pvt.ltd',40000,'123 main st karachi',0001),
(202,'hassan','abc ltd',50000,'456 first st lahore',0002),
(203,'hamza','pqr corporation',60000,'789 second st islamabad',0003)
6. selectList orders over 2500, including the name of the sales person
who took the order and the name of the customer who placed it:

SELECT o.Order_id, s.SalRep_Name, c.customer_Name


FROM Ordersg o
JOIN SalesRepg s ON o.Sal_Rep_id = s.Sal_Rep_id
JOIN Customerg c ON o.Customer_id = c.Customer_id
WHERE o.Amount > 2500;

create table SalesRepk


(
sal_rep_id int primary key,
SalRep_name varchar(255),
Office_id int,
title varchar(255),
age int,
hiredate date,
manager int,
quota int,
sales int,
target int,
)

insert into
SalesRepk(sal_rep_id,SalRep_name,office_id,title,age,hiredate,manager
,quota,sales,target)
values
(01,'ali',101,'sales manager',35,'2023-03-14',null,40000,45000,50000),
(02,'hassan',102,'senior sales executive',36,'2024-05-
15',2001,55000,60000,65000),
(03,'shazal',103,'sales executive',23,'2024-05-
08',2002,30000,35000,40000)

List the names of sales people and their managers:


select*from SalesRepk
SELECT s.SalRep_Name, m.SalRep_Name AS ManagerName
FROM SalesRepk s
JOIN SalesRepk m ON s.Manager = m.Sal_Rep_id;

You might also like