Anda di halaman 1dari 6

DATABASE SYSTEM MANAGEMENT ASSIGNMENT

Set 1.

Consider the following relation schema for the SALES database:

CUSTOMER (CustNo, CName, City)

ORDERED (OrderNo, OrderDate, CustNo, Amount)

ORDER_ITEM (OrderNo, ItemNo, Qty)

ITEM (ItemNo, UnitPrice)

ORDERED

ORDERNO ORDERDATE CUSTNO AMOUNT

F200 02-09-2017 C002 720


F001 10-05-2017 C001 2800
F300 15-11-2017 C003 1600
F400 21-04-2017 C004 1100
F500 12-01-2017 C005 2500
F600 10-01-2017 C006 2100

ORDER_ITEM CUSTOMER

ORDERNO ITEMNO QTY CUSTO CNAME CITY


F300 I237 80
C001 Ankush Malda
F600 I010 30
C002 Babin Madras
F200 I192 10
C003 John Taxes
F500 I700 50
F001 I010 40 C004 Navathe Pune
F400 I528 20 C006 Elmsari Atlanta
C005 Sahani Atlanta
ITEM

ITEMNO UNITPRICE

I237 20
I192 72
I010 70
I700 50
I528 55

On the basis of this relational schema write the following queries in Structured Query Language.
(a) Retrieve the number and date of orders placed by customers residing at Atlanta city.

ANS: SELECT O.OrderNo,O.OrderDate

FROM ORDERED O, CUSTOMER C

WHERE ((C.CustNo=O.CustNo) and

(C.City='Atlanta'));

OUTPUT:

ORDERNO ORDERDATE

F500 12-01-2017
F600 10-01-2017

(b) Retrieve the number and unit price of items for which an order of quantity greater than 50 is
placed.

ANS: SELECT I.ItemNo,I.UnitPrice

FROM ORDER_ITEM O,ITEM I

WHERE((O.ItemNo=I.ItemNo)and

(O.qty > 50));

OUTPUT:

ITEMNO UNITPRICE

I237 20

(c) Retrieve the order number, date and Item number for the order of Items having a unit price
greater than 20.

ANS: SELECT O.OrderNo, O.OrderDate, I.ItemNo

FROM ORDERED O, ORDER_ITEM T, ITEM I

WHERE ((O.OrderNo=T.OrderNo) and

(T.ItemNo=I.ItemNo) and

(I.UnitPrice > 20));


OUTPUT:

ORDERNO ORDERDATE ITEMNO

F200 02-09-2017 I192


F001 10-05-2017 I010
F400 21-04-2017 I528
F500 12-01-2017 I700
F600 10-01-2017 I010

(d) Retrieve details of customers who have placed an order for the item number IO1O.

ANS: SELECT C.CustNo,CName,city

FROM CUSTOMER C, ORDERED O,ORDER_ITEM T

WHERE ((C.CustNo = O.CustNo) and

(O.OrderNo = T.OrderNo)and

(T.ItemNo = 'I010'));

OUTPUT:

CUSTNO CNAME CITY

C001 Ankush Malda

C006 Elmsari Atlanta

(e) Retrieve the number and unit price of items for which an order is placed by the customer number
COO1.

ANS: SELECT I.ItemNo,I.UnitPrice

FROM ITEM I,ORDER_ITEM T

WHERE ((T.ItemNo = I.ItemNo) and T.OrderNo IN

(SELECT OrderNo

FROM CUSTOMER C, ORDERED O


WHERE(O.CustNo = C.CustNo) and

C.CustNo = 'C001'));

OUTPUT:

ITEMNO UNITPRICE

I010 70

Set 2.

Consider the following relational database:

EMPLOYEE (Empname, Street, City)

WORKS (Empname, Companyname, Salary)

COMPANY (Companyname, City)

MANAGES (Empname , Managername)

On the basis of this relational schema write the following queries in Structured Query Language.

(a) Find the names of all employees who work for First Bank Corporation.

(b) Find the names, street addresses and cities of residence of all employees who work for First Bank
Corporation and earn more than 100,000 per annum.

(c) Find the names of all employees in this database who live in the same city as the company for
which they work,

(d) Find the number of employees working in each company.

(e) Find the average, maximum and minimum salary for each con1pany.
Set 3.

Consider the following relation schema for the BANK database:

BRANCH (BranchID, Bname, City, Phone)

ACCOUNT (AccountNo, Aname, AType, BranchID, Balance)

TRANSACTION (TID, T_Date, T_Type, AccountNo, Amount)

On the basis of this relational schema, write the following queries in Structured Query Language.

(a) Retrieve the ID and name of all the branches located in ‘Seattle’ city.

(b) Retrieve the ID, type and amount of all the transactions of withdrawal type.

(c) List the number and type of all accounts opened in the branch having ID B010.

(d) List the number and name of account holders withdrawing an amount greater than 10,000 on
31st March, 2007.

(e) List the number and name of account holders having savings account in the city
Los Angeles.

(f) Calculate the average balance of accounts present in the AX International Bank in New York.

(g) Calculate the maximum and minimum balance of accounts in each city.

Anda mungkin juga menyukai