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

draw traceability matrix for online shopping system ( online grocery store)
draw traceability matrix for online shopping system ( online grocery store)
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.
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...
. 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....
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 an online reservation system for a bus company. The bus company includes several buses and...
Consider an online reservation system for a bus company. The bus company includes several buses and realizes trips to different cities. Each bus is identified by its plate number and a separately assigned bus number. The trips are based on a predefined schedule and stop at predefined bus stations. Each bus can have only one trip per day. Each bus includes a driver and one hostess. For long trips, the bus will have breaks at service and rest areas. There...
Presented below are the 2020 Income Statement and Balance Sheet for Riggins Online Store. Prepare a...
Presented below are the 2020 Income Statement and Balance Sheet for Riggins Online Store. Prepare a Cash Flow Statement as of December 31, 2020. Additional Information for the 2020 fiscal year includes: 1) Cash dividends of $1,000 were declared and paid. 2) Equipment with a cost of $1,500 and accumulated depreciation of $1,000 was sold for $500. Riggins Online Store Income Statement For the Year Ended December 31, 2020 Sales Revenue $ 14,250 Service Revenue       3,400 Total Revenue $...
The table below defines number of working activities needed to accomplish a House project. The relationships...
The table below defines number of working activities needed to accomplish a House project. The relationships or dependencies between predecessors and successors activities are all defined as "finish to start" type. Dependency Duration in days I.D Activity name ................................ 20 A Excavation work A 5 B Plain concrete work A 6 C Reinforced concrete work B & C 2 D Install grass C 10 E Build walls E 8 F Build roof E 7 G Plaster work F & G...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT