Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CREATE TABLE customer ( customer_id INTEGER NOT NULL, customer_name VARCHAR (25) NOT NULL, address_line_1 VARCHAR (200), city VARCHAR (100), state_province CHAR (25), postal_code VARCHAR (50),

CREATE TABLE customer ( customer_id INTEGER NOT NULL,

customer_name VARCHAR (25) NOT NULL,

address_line_1 VARCHAR (200),

city VARCHAR (100),

state_province CHAR (25),

postal_code VARCHAR (50),

PRIMARY KEY (customer_id) ) ;

CREATE TABLE order_header ( order_id INTEGER NOT NULL,

order_date DATE,

customer_id INTEGER,

PRIMARY KEY (order_id),

CONSTRAINT order_fkey_customer_id FOREIGN KEY (customer_id) REFERENCES customer (customer_id)) ;

CREATE TABLE product ( product_id INTEGER NOT NULL,

product_name VARCHAR (200),

product_line VARCHAR (200),

product_price DECIMAL(19,2),

PRIMARY KEY (product_id) ) ;

CREATE TABLE order_line ( order_id INTEGER NOT NULL,

product_id INTEGER NOT NULL,

quantity INTEGER,

PRIMARY KEY (order_id,

product_id),

CONSTRAINT order_line_fkey_order_id FOREIGN KEY (order_id) REFERENCES order_header (order_id),

CONSTRAINT order_line_fkey_product_id FOREIGN KEY (product_id) REFERENCES product (product_id)) ;

Create a query that uses a Common Table Expression (CTE) and a Window Function to find the last (most recent) customer in each city to place an order. Your query should return the following columns:

-- last_customer_name (split the name into first and last names, use the last name)

-- city

-- (Hints: Try the RANK function. Make sure to handle customers with 3 names. )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

ISBN: 0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago

Question

What is Indian Polity and Governance ?

Answered: 1 week ago