Question

In: Computer Science

Below are several table schemas representing online store delivery system, with attributes and relationships: You will...

Below are several table schemas representing online store delivery system, with attributes and relationships: You will use these to answer the SQL questions 1-7. (2 marks each).

Shopper (shopperNo(pk), shopperfName, shopperlName, shopperContact, shopperCity, shopperCcard);

Store (storeNo(pk), storeLocation, storeSize)

Review (revCode(pk), revDate, revRating, shopperNo, storeNo(fk))

Purchase (purId(pk), purDate, purTime, purQty, purValue, shopperNo(fk), storeNo(fk)))

Use SQL statements to answer the following questions:

  1. Use SQL statements to create the 2 tables: Purchase and Store with the correct relationship constraints.
  2. Add 2 rows:
    1. One row in STORE with one store having number ‘99’.
    2. Another row in SHOPPER with your student full name and student ID.
  3. List the shoppers (shopperNo, shopperfName, shopperlName ) who have not given any reviews; sort the results by fName and lName in ascending order.
  4. Show the number of times that each shopper made a purchase. Sort the results by the shopperNo.
  5. List the storeNo and storeLocation for all stores that had a purchase order on 10/5/2020.
  6. Show the total amount of the purchases made in store ‘99’ to display, if the total purchase value is more than $400.
  7. For the purchase table, we need to change the purchase quantity to ‘30’ for the shopper ‘2556’: write an SQL statement to make this change.

Below are several table schemas representing online store delivery system, with attributes and relationships: You will use these to answer the SQL questions 1-7. (2 marks each).

Shopper (shopperNo(pk), shopperfName, shopperlName, shopperContact, shopperCity, shopperCcard);

Store (storeNo(pk), storeLocation, storeSize)

Review (revCode(pk), revDate, revRating, shopperNo, storeNo(fk))

Purchase (purId(pk), purDate, purTime, purQty, purValue, shopperNo(fk), storeNo(fk)))

Use SQL statements to answer the following questions:

  1. Use SQL statements to create the 2 tables: Purchase and Store with the correct relationship constraints.
  2. Add 2 rows:
    1. One row in STORE with one store having number ‘99’.
    2. Another row in SHOPPER with your student full name and student ID.
  3. List the shoppers (shopperNo, shopperfName, shopperlName ) who have not given any reviews; sort the results by fName and lName in ascending order.
  4. Show the number of times that each shopper made a purchase. Sort the results by the shopperNo.
  5. List the storeNo and storeLocation for all stores that had a purchase order on 10/5/2020.
  6. Show the total amount of the purchases made in store ‘99’ to display, if the total purchase value is more than $400.
  7. For the purchase table, we need to change the purchase quantity to ‘30’ for the shopper ‘2556’: write an SQL statement to make this change.

Solutions

Expert Solution

To create table, use the syntax, CREATE TABLE table_name (column datatype);

CREATE TABLE Purchase (
purId int NOT NULL PRIMARY KEY,
purDate DATE NOT NULL,
purTime TIME (0) NOT NULL,
purQty int,
purValue int,
FOREIGN KEY (shopperNo) REFERENCES Shopper(shopperNo),
FOREIGN KEY (storeNo) REFERENCES Store(storeNo)
);

Similarly create Store table,

CREATE TABLE Store (
storeNo int NOT NULL PRIMARY KEY,
storeLocation char(255),
storeSize int,
);

To insert values in the table, use the syntax INSERT INTO table_name (column)VALUES (value);
INSERT INTO Store VALUES (99, 'mount road,XYZ', 100);
INSERT INTO Shopper(shopperNo, shopperfName, shopperlName) VALUES (123, 'Abc', 'Def');

To get result from combining two or more tables Join or where can be used.

Here, we used where and in to combine results.

select shopperNo, shopperfName, shopperlName from Shopper A where
A.shopperNo in (
select B.shopperNo from Review B where B.revRating IS NULL);

To calculate the number of times that each shopper made a purchase, COUNT() is used.

Group by groups shopperNo and order by sort them.
  
SELECT shopperNo,COUNT(purId)
FROM Review
GROUP BY shopperNo
ORDER BY COUNT(purId));

where A.storeNo in is used to link Store table to Purchase.
select storeNo, storeLocation from Store A where
A.storeNo in (
select B.storeNo from Purchase B where B.purDate = '10/5/2020');

Here, where A.storeNo in is used to link Purchase and Store table.
  
select purId, purQty from Purchase A where purValue > 400 AND
A.storeNo in (select B.storeNo from Store B where B. storeNo = 99);

To update a existing row in a table,UPDATE table_name
SET column1 = value1 WHERE condition;
  
UPDATE Purchase SET purQty = 30 WHERE shopperNo='2556';


Related Solutions

The table below summarizes the costs and benefits for a new online procurement system. Based on...
The table below summarizes the costs and benefits for a new online procurement system. Based on these estimates: Create a spreadsheet showing the Net Present Value for the costs and benefits listed. Use NPV values for the calculations below. Calculate the return on investment for this project. Calculate the payback period for this project. Calculate the internal rate of return for this project. Based on these calculations would you recommend undertaking this project? Why? What factors other than financial metrics...
draw traceability matrix for online shopping system ( online grocery store)
draw traceability matrix for online shopping system ( online grocery store)
USING SQL Create a table named Zones with the attributes and assumptions indicated below. Attributes: the...
USING SQL Create a table named Zones with the attributes and assumptions indicated below. Attributes: the zone ID, the lowest and the highest accepted temperature. Assumptions: the ID will be the primary key and have one or two digits, the temperatures (in Fahrenheit) will be at most two digits and a possible minus sign, none of the temperatures can be NULL. Populate table Zones so that it has the following rows: id lowerTemp higherTemp 2 -50 -40 3 -40 -30...
Read the document “Organizing the Health Care Delivery System for Performance” and the 6 attributes they...
Read the document “Organizing the Health Care Delivery System for Performance” and the 6 attributes they feel are necessary for high performance. Choose one of the models of organizing for high performance and describe strategies that have proven effective in creating an integrated high performance health system within that model.
. Lucie the peafowl is hiring delivery drivers for their new hummusat-home online store. There are...
. Lucie the peafowl is hiring delivery drivers for their new hummusat-home online store. There are 43 applicants, of whom 16 are goats. Lucie hires 12 drivers, including only one goat. a. What is the probability that Lucie would hire exactly one goat, assuming they don’t care if a driver is a goat or not. b. What is the probability that Lucie would hire no goats at all, assuming they don’t care if a driver is a goat or not....
You are given the following schemas for a corporation database. The corporation owns several subsidiary companies...
You are given the following schemas for a corporation database. The corporation owns several subsidiary companies (e.g. Disney Corporation owns Lucasfilm Ltd). Managers are also Employees. Answer the following questions using the schemas. Employee(ssn, name, street, city) Company(company_name, asset) Company_Branches(company_name, branch_num, city) Works(ssn, company_name, branch_num, salary) Managed_By(ssn, manager_ssn) 6) Does the current design allow us to enforce the constraint that each employee must have a manager (without using external check or triggers)? Why or why not? 7) If the answer...
1. System Schemas: PLEASE BE DETAILED WITH EXPLANATIONS! a. Suppose you are sitting in a car...
1. System Schemas: PLEASE BE DETAILED WITH EXPLANATIONS! a. Suppose you are sitting in a car that is speeding up. Draw a system schema for this situation. Then draw well-separated force diagrams (free-body diagrams) of the following objects: - your own body; - the seat in which you are sitting (apart from the car); - the car (apart from the seat); - the road surface where the tires and the road interact. b) Assume the car has rear wheel drive....
Database System Question An automobile part trading company would like to store the following attributes for...
Database System Question An automobile part trading company would like to store the following attributes for each part in a database table: PartNo: 10 bytes Name: 30 bytes UintMeasure: 5 bytes UnitCost: 4 bytes UnitPrice: 4 byes QtyOnHand: 4 bytes QtyOnOrder: 4bytes PreferredSupplier: 30 bytes Consider a disk with block size of 512 bytes and block pointer of 6 bytes long. Each record has a unique value of PartNo. There are altogether 50,000 parts in the company. Compute the following:...
The table below shows a dataset representing the ages of employees working for three different districts....
The table below shows a dataset representing the ages of employees working for three different districts. Assuming a minimum working age of 18 and a mandatory retirement age of 65: Ages for Employees Working for Three Districts District A 35 25 44 62 55 22 31 41 36 65 District B 47 37 25 24 22 31 33 35 27 36 District C 20 40 40 35 42 47 50 52 54 60 What is the possible age range for...
Consider the following un-normalized relational table on an online retail store orders and payments information: An...
Consider the following un-normalized relational table on an online retail store orders and payments information: An online retail store would like to create a database to keep track of its sales activities. Information recorded in the database supposed to include customer number that identifies each customer, customer’s first name, last name, unique order number of orders a customer made, the date when an order was made, unique product number of products included in orders, product description, sequence number listing the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT