Question: CREATE TABLE Customers ( customer_id TEXT, - customer_id customer_postal_code INTEGER, - customer_zip_code_prefix PRIMARY KEY(customer_id) ); CREATE TABLE Sellers ( seller_id TEXT, -- seller_id seller_postal_code INTEGER,

CREATE TABLE "Customers" ( "customer_id" TEXT, - customer_id "customer_postal_code" INTEGER, - customer_zip_code_prefix PRIMARY KEY("customer_id") );

CREATE TABLE "Sellers" ( "seller_id" TEXT, -- seller_id "seller_postal_code" INTEGER, -- seller_zip_code_prefix PRIMARY KEY("seller_id") );

CREATE TABLE "Orders" ( "order_id" TEXT, -- order_id "customer_id" TEXT, -- customer_id PRIMARY KEY("order_id"), FOREIGN KEY("customer_id") REFERENCES "Customers"("customer_id") );

CREATE TABLE "Order_items" ( "order_id" TEXT, -- order_id "order_item_id" INTEGER, - order_item_id "product_id" TEXT, -- product_id "seller_id" TEXT, -- seller_id PRIMARY KEY("order_id","order_item_id","product_id","seller_id"), FOREIGN KEY("seller_id") REFERENCES "Sellers"("seller_id") FOREIGN KEY("order_id") REFERENCES "Orders"("order_id") );

Please do only Q3.Thanks

Q1: Given a random customer_postal_code from Customers, find how many orders containing more than 1 item have been placed by customers who have that customer_postal_code.

Q2: Create a VIEW called OrderSize which has two columns, oid and size, where oid is an order_id and size is the total number of items in that order. Using the view OrderSize, extend Q1 with the orders that have items more than the average number of items in the orders.

Q3: Rewrite query Q2 but not using any VIEW.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!