Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello! Help with SQL , please! We have following tables from database _ adventureworkslt: CREATE TABLE public.product ( productid serial 4 NOT NULL, name varchar

Hello! Help with SQL, please!
We have following tables from database _adventureworkslt:
CREATE TABLE public.product (
productid serial4 NOT NULL,
"name" varchar(50) NOT NULL,
productnumber varchar(25) NOT NULL,
color varchar(15) NULL,
listprice numeric(29,3) NOT NULL,
"size" varchar(5) NULL,
sizeunitmeasurecode bpchar NULL,
weightunitmeasurecode bpchar NULL,
weight numeric(8,2) NULL,
productline bpchar NULL,
"class" bpchar NULL,
"style" bpchar NULL,
productsubcategoryid int4 NULL,
productmodelid int4 NULL,
sellstartdate timestamp(6) NOT NULL,
sellenddate timestamp(6) NULL,
discontinueddate timestamp(6) NULL,
CONSTRAINT product_pkey PRIMARY KEY (productid)
);
CREATE INDEX idx_product_color ON public.product USING btree (color);
CREATE TABLE public.productsubcategory (
productsubcategoryid serial4 NOT NULL,
productcategoryid serial4 NOT NULL,
"name" varchar(54) NOT NULL,
CONSTRAINT productsubcategory_pkey PRIMARY KEY (productsubcategoryid)
);
CREATE TABLE public.productcategory (
productcategoryid serial4 NOT NULL,
"name" varchar(54) NOT NULL,
CONSTRAINT productcategory_pkey PRIMARY KEY (productcategoryid)
);
CREATE TABLE public.customer (
customerid int4 NOT NULL,
namestyle bool DEFAULT false NOT NULL,
title varchar(8) NULL,
firstname varchar(50) NULL,
middlename varchar(50) NULL,
lastname varchar(50) NULL,
suffix varchar(10) NULL,
companyname varchar(128) NULL,
emailaddress varchar(50) NULL,
rowguid varchar(36) NOT NULL,
modifieddate timestamp(6) DEFAULT CURRENT_TIMESTAMP NOT NULL,
salespersonid int4 NULL,
gender varchar(1) NULL,
totalchildren int4 NULL,
birthdate date NULL,
datefirstpurchase date NULL,
persontype varchar(3) NULL,
CONSTRAINT customer_pkey PRIMARY KEY (customerid)
);
CREATE TABLE public.customeraddress (
customerid int4 NOT NULL,
addressid int4 NOT NULL,
addresstype varchar(50) NOT NULL,
modifieddate timestamp(6) DEFAULT CURRENT_TIMESTAMP NOT NULL,
CONSTRAINT customeraddress_pk PRIMARY KEY (customerid, addressid, addresstype)
);
ALTER TABLE public.customeraddress ADD CONSTRAINT customeraddress_c_fk FOREIGN KEY (customerid) REFERENCES public.customer(customerid);
ALTER TABLE public.customeraddress ADD CONSTRAINT customeraddress_fk FOREIGN KEY (addressid) REFERENCES public.address(addressid);
Add two materialized views product2,country2. Product2 should combine data of product and
its category. Country2 view should be filled with unique codes of the countries where the shops are
located (country codes can be taken from addresses of Main Office type(addresstype)).
Allow managers and administrators to read from these views.
Fields of product2 are shown in the table. Each field to be included in the view is described below:
Field Description Rule
----------------------------------------------------------------------------
pcid |Product category key |Load from Productcategory.productcategoryid
productid |Product key |Load from Product.productid
pcname |Category name |Load from Productcategory.name
pname |Product name |Load from Product.name
Fields of 'country2' are shown in the table:
Field Description Rule
----------------------------------------------------
countrycode |Code of country |Load unique values from customeraddress.countreyregioncode
Make sure your query reads only Main Office addresses (addresstype)

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

Database Systems For Advanced Applications 27th International Conference Dasfaa 2022 Virtual Event April 11 14 2022 Proceedings Part 2 Lncs 13246

Authors: Arnab Bhattacharya ,Janice Lee Mong Li ,Divyakant Agrawal ,P. Krishna Reddy ,Mukesh Mohania ,Anirban Mondal ,Vikram Goyal ,Rage Uday Kiran

1st Edition

3031001257, 978-3031001253

More Books

Students also viewed these Databases questions

Question

=+43-3 Discuss how stress makes us more vulnerable to disease.

Answered: 1 week ago