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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started