Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Assignment Information The following relational schema (primary keys are underlined) are used by the security company, West Park, described in Assignment 1, with some

image text in transcribed
image text in transcribed
The Assignment Information The following relational schema (primary keys are underlined) are used by the security company, West Park, described in Assignment 1, with some minor modifications. Stores(sid, name, address, phone) Products(barcode, name, description, price) Members(mid, name, contactinfo, openAtStore, open Time, lastRenew Time) Transactions(sid, pid, transaction Time, customer, employee) TransactionContent(sid, pid, barcode) Return Transactions(returnStore, returnPid, sid, pid, barcode, return Time, returnComment, employee) This assignment is based on the above relational schema. Many details, including foreign keys, data types, etc, are captured in the SQL definition of these tables. Express each of the following queries in SQL against the relational schema defined above. Each query should be expressed using a single SQL statement. (4 marks for each SQL query.) 1. For each customer, list his/her name, contact information, and the total number of purchase transactions done by him/her during January 1st, 2019 and December 31, 2019 (inclusive). If the customer didn't make any purchase in that period, still show his/her name and contact information, and list 0 as the total number purchase transactions. 2. For each purchase transaction, list the name of the customer who made the purchase, the transaction time, the number of product items purchased in this transaction and the total amount involved in this purchase. The total amount is calculated as the sum of the price of each product purchased in this transaction. 3. List the name and contact information of each customer who has done more than 10 purchase transactions. Order the results according to the number of purchase transactions done by the customer in descending order. 4. List the name, description and price of the most expensive product. 5. List the address and phone number of the store which has the most number of members. That is, the most number of customers chose this store to open his/her membership account. CREATE TABLE Stores ( sid NUMBER(5) PRIMARY KEY, name VARCHAR2(100) NOT NULL, address VARCHAR2 (200), phone CHAR(10) ); CREATE TABLE Products barcode CHAR(10) PRIMARY KEY, name VARCHAR2 (30) NOT NULL, description VARCHAR2 (200), price NUMBER (8, 2) NOT NULL CREATE TABLE Members mid NUMBER (12) PRIMARY KEY, name VARCHAR2 (30) NOT NULL, contact Info VARCHAR2 (100), openAt Store NUMBER(5) REFERENCES Stores, openTime DATE, lastRenewTime DATE CREATE TABLE Transactions sid NUMBER (5) REFERENCES Stores, pid NUMBER (10), transaction Time DATE, customer NUMBER (12) REFERENCES Members, employee CHAR(6), PRIMARY KEY (sid, pid) CREATE TABLE TransactionContent sid NUMBER(5), pid NUMBER(10), barcode CHAR(10) REFERENCES Products, PRIMARY KEY (sid, pid, barcode), FOREIGN KEY (sid, pid) REFERENCES Transactions CREATE TABLE Return Transactions ( returnStore NUMBER(5) REFERENCES Stores, returnPid NUMBER (10), sid NUMBER (5), pid NUMBER (10), barcode CHAR(10), return Time DATE, returnComment VARCHAR2 (200), employee CHAR(6), PRIMARY KEY (returnStore, returnPid), FOREIGN KEY (sid, pid, barcode) REFERENCES TransactionContent

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

2. How can competencies be used in employee development?

Answered: 1 week ago