Question: 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

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!