You are on page 1of 3

Consider an ONLINE_AUCTION database system in which members (buyers and sellers)

participate in the sale of items. The data requirements for this system are
summarized
as follows:
 The online site has members, each identified by a unique member
number and described by an e-mail address, name, password, home address,
and phone number.
 A member may be a buyer or a seller. A buyer has a shipping address recorded
in the database. A seller has a bank account number and routing number
recorded in the database.
 Items are placed by a seller for sale and are identified by a unique item number
assigned by the system. Items are also described by an item title, a description,
starting bid price, bidding increment, the auction's start date, and the auction's
end date.
 Items are also categorized based on a fixed classification hierarchy (for
example,
a modem may be classified as COMPUTER → HARDWARE → MODEM).
 Buyers make bids for items they are interested in. Bid price and time of bid are
recorded. The bidder with the highest bid price at the end of the auction is
declared the winner, and a transaction between buyer and seller may
proceed.
 The buyer and seller may record feedback regarding their completed
transactions. Feedback contains a rating of the other party participating in the
transaction (1–10) and a comment.
Design an entity–relationship diagram for the mail-order database and Convert it
into a
Schema diagram.
Identify the appropriate functional requirements for the above database, write the
SQL
queries, and show the results.
Objectives of the Assignment
 Apply ER concepts to draw the ER diagram
 Apply the Mapping algorithm to convert ER to Relational Model
 Create the database for the given relational model
 Write the SQL queries for retrieving the data from the database.
Expected outcomes
1. Complete ER diagram with structural constraints
2. Schema diagram with all the constraints.
3. Database with sufficient records (minimum 20 records in each table)
4. SQL Queries should cover the following
i) Aggregate functions
ii) Complex queries
iii) Simple Nested and Correlated queries.
iv) Six clauses
Unfortunately, as a text-based AI language model, I am not able to provide a visual
ER diagram or schema diagram. However, I can assist you with the following tasks:

Identifying structural constraints:


A member can only be either a buyer or a seller, not both.
Each member is uniquely identified by a member number.
Each item is uniquely identified by an item number.
Each bid is linked to a specific item and a specific buyer.
Each feedback is linked to a specific transaction between a specific buyer and a
specific seller.
Converting the ER diagram to a relational model:
Table "Members" with columns: MemberID (Primary Key), Email, Name, Password,
HomeAddress, PhoneNumber, ShippingAddress (for buyers only), BankAccountNumber (for
sellers only), RoutingNumber (for sellers only).
Table "Items" with columns: ItemID (Primary Key), Title, Description, StartBid,
BidIncrement, StartDate, EndDate, SellerID (Foreign Key referencing
Members.MemberID).
Table "Categories" with columns: CategoryID (Primary Key), CategoryName,
ParentCategoryID (Foreign Key referencing Categories.CategoryID).
Table "ItemCategories" with columns: ItemID (Foreign Key referencing Items.ItemID),
CategoryID (Foreign Key referencing Categories.CategoryID).
Table "Bids" with columns: BidID (Primary Key), ItemID (Foreign Key referencing
Items.ItemID), BuyerID (Foreign Key referencing Members.MemberID), BidPrice,
BidTime.
Table "Transactions" with columns: TransactionID (Primary Key), ItemID (Foreign Key
referencing Items.ItemID), BuyerID (Foreign Key referencing Members.MemberID),
SellerID (Foreign Key referencing Members.MemberID), TransactionTime.
Table "Feedback" with columns: FeedbackID (Primary Key), TransactionID (Foreign Key
referencing Transactions.TransactionID), BuyerID (Foreign Key referencing
Members.MemberID), SellerID (Foreign Key referencing Members.MemberID), Rating,
Comment.
Sample SQL queries:
SELECT AVG(Rating) FROM Feedback WHERE SellerID = [SellerID]; (Aggregate function)
SELECT Members.Name, Items.Title, Bids.BidPrice, Transactions.TransactionTime FROM
Members INNER JOIN Bids ON Members.MemberID = Bids.BuyerID INNER JOIN Items ON
Bids.ItemID = Items.ItemID INNER JOIN Transactions ON Bids.BuyerID =
Transactions.BuyerID AND Bids.ItemID = Transactions.ItemID WHERE Members.Name =
[BuyerName]; (Complex query)
SELECT Members.Name, (SELECT AVG(Rating) FROM Feedback WHERE Feedback.SellerID =
Members.MemberID) AS AverageRating FROM Members WHERE MemberID = [SellerID];
(Simple nested query)
SELECT Members.Name, Transactions.TransactionTime, (SELECT MAX(BidPrice) FROM Bids
WHERE Bids.ItemID = Transactions.ItemID) AS MaxBid FROM Members INNER JOIN
Transactions ON Members.MemberID = Transactions.BuyerID WHERE Members.Name =
[BuyerName]; (Correlated query)
SELECT Members.Name, Transactions.TransactionTime FROM Members INNER JOIN
Transactions ON Members.MemberID = Transactions.BuyerID WHERE
Transactions.TransactionTime BETWEEN [StartDate] AND [EndDate] ORDER BY
Transactions.TransactionTime DESC; (SELECT with ORDER BY clause)
SELECT Members.Name, Transactions.Transaction

Ankit Kumar
continue
Complex Queries:

Find the average rating given by all the buyers for each seller:
vbnet
Copy code
SELECT seller.seller_id, AVG(feedback.rating) as avg_rating
FROM seller
JOIN feedback ON seller.seller_id = feedback.seller_id
GROUP BY seller.seller_id;
Find the item title, item description, and name of the highest bidder for each
item:
vbnet
Copy code
SELECT item.item_id, item.item_title, item.item_description, member.name,
MAX(bid.bid_price) as max_bid
FROM item
JOIN bid ON item.item_id = bid.item_id
JOIN member ON bid.member_id = member.member_id
GROUP BY item.item_id;
Simple Nested and Correlated Queries:

Find all the items for which the current bid price is higher than the starting bid
price:
sql
Copy code
SELECT item_id, item_title, item_description
FROM item
WHERE starting_bid_price < (SELECT MAX(bid_price) FROM bid WHERE item.item_id =
bid.item_id);
Find all the items for which the current bid price is lower than the starting bid
price:
sql
Copy code
SELECT item_id, item_title, item_description
FROM item
WHERE starting_bid_price > (SELECT MAX(bid_price) FROM bid WHERE item.item_id =
bid.item_id);
SQL Clauses:

Find all the items for which the auction end date is today and order the results by
the starting bid price in descending order:
sql
Copy code
SELECT item_id, item_title, item_description
FROM item
WHERE end_date = CURDATE()
ORDER BY starting_bid_price DESC;
Find all the items for which the auction start date is before today and the auction
end date is after today and order the results by the starting bid price in
ascending order:
scss
Copy code
SELECT item_id, item_title, item_description
FROM item
WHERE start_date < CURDATE() AND end_date > CURDATE()
ORDER BY starting_bid_price ASC;
Note: This is just a sample of the SQL queries that can be written for the given
system. There can be many other ways to retrieve the required data from the
database.

You might also like