Question
CREATE TABLE Customers ( customer_id TEXT, - customer_id customer_postal_code INTEGER, - customer_zip_code_prefix PRIMARY KEY(customer_id) ); -- olist_sellers_dataset.csv CREATE TABLE Sellers ( seller_id TEXT, -- seller_id
CREATE TABLE "Customers" ( "customer_id" TEXT, - customer_id "customer_postal_code" INTEGER, - customer_zip_code_prefix PRIMARY KEY("customer_id") ); -- olist_sellers_dataset.csv CREATE TABLE "Sellers" ( "seller_id" TEXT, -- seller_id "seller_postal_code" INTEGER, -- seller_zip_code_prefix PRIMARY KEY("seller_id") ); -- olist_orders_dataset.csv 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") ); -- olist_order_items_dataset.csv 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") ); SOLVE Q3 please
Q1: Given a random customer_postal_code from Customers, find how many orders 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 information of the average number of items each order had. 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