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

ASSIGNMENT SQL

a. The following tables form part of a database held in a relational DBMS. Based on the
following table structure, create SQL statement for each of the following questions.
SALESPERSON
SalesID
1
2
3
4
5
6

Name
Abel
Baker
Jones
Murphy
Zenith
Kobad

Age
63
38
26
42
59
27

Salary
120,000
42,000
36,000
50,000
118,000
34,000

ORDER
OrderNo

CustName

100
200
300
400
500
600
700

10
10
20
40
10
30
20

CUSTOMER
CustID
10
20
30
40

SalespersonNa
me
5
3
1
1
4
1
3

Name
Abernathy Construction
Manchester Lumber
Tri-City Builders
Amalgamated Housing

Amount
560
1800
480
2500
6000
700
150

City
Willow
Manchester
Memphis
Memphis

IndustryType
B
F
B
B

i. List full details of all Salesperson, alphabetically ordered by name.


Select * from salesperson order by name;
SalesID
1
2
3
6
4
5

Name
Abel
Baker
Jones
Kobad
Murphy
Zenith

Age
63
38
26
27
42
59

Salary
120,000
42,000
36,000
34,000
50,000
118,000

ii.Compute the average age of a Salesperson.


Select avg(age) from salesperson;
SALESPERSON
Avg
42.5

iii.

Compute the number of Customer(s) that make orders more than 1000.

SELECT CustID,SUM(amount) FROM Order


GROUP BY Customer
HAVING SUM(amount)>1000
ORDER
CustID
10
40

Amount
8360
2500

iv. Show the names and salary of all Salesperson who do not have an order with
Abernathy Construction.
Select distinct s.name, s.salary
from salesperson s, order o
where s.name=o.salespersonName
AND o.custName != Abernathy Construction;
SALESPERSON
Name
Salary
Abel
120,000

Jones

36,000

v.Show the age of Salesperson who have an order with a Customer in Memphis.

Select distinct s.age


from salesperson s, orders o, customer c
where c.city=Memphis
AND c.name=o.custName
AND o.salespersonName=s.name;
vi.

Delete all orders for Abernathy Construction.

Delete from orders where custName=Abernathy Construction;

vii.

Insert new record into table Customer using the following data:
Name = WestCourt Furniture
City = London
Industry Type = F

Insert into customer values (WestCourt, London, F);


viii.

Change the record of Salesperson named Jones into new data as following:
Name = Parks
Age = 30

Update salesperson set name=Parks, age=30 where name=Jones;

You might also like