Answered step by step
Verified Expert Solution
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 serial NOT NULL,
"name" varchar NOT NULL,
productnumber varchar NOT NULL,
color varchar NULL,
listprice numeric NOT NULL,
"size" varchar NULL,
sizeunitmeasurecode bpchar NULL,
weightunitmeasurecode bpchar NULL,
weight numeric NULL,
productline bpchar NULL,
"class" bpchar NULL,
"style" bpchar NULL,
productsubcategoryid int NULL,
productmodelid int NULL,
sellstartdate timestamp NOT NULL,
sellenddate timestamp NULL,
discontinueddate timestamp NULL,
CONSTRAINT productpkey PRIMARY KEY productid
;
CREATE INDEX idxproductcolor ON public.product USING btree color;
CREATE TABLE public.productsubcategory
productsubcategoryid serial NOT NULL,
productcategoryid serial NOT NULL,
"name" varchar NOT NULL,
CONSTRAINT productsubcategorypkey PRIMARY KEY productsubcategoryid
;
CREATE TABLE public.productcategory
productcategoryid serial NOT NULL,
"name" varchar NOT NULL,
CONSTRAINT productcategorypkey PRIMARY KEY productcategoryid
;
CREATE TABLE public.customer
customerid int NOT NULL,
namestyle bool DEFAULT false NOT NULL,
title varchar NULL,
firstname varchar NULL,
middlename varchar NULL,
lastname varchar NULL,
suffix varchar NULL,
companyname varchar NULL,
emailaddress varchar NULL,
rowguid varchar NOT NULL,
modifieddate timestamp DEFAULT CURRENTTIMESTAMP NOT NULL,
salespersonid int NULL,
gender varchar NULL,
totalchildren int NULL,
birthdate date NULL,
datefirstpurchase date NULL,
persontype varchar NULL,
CONSTRAINT customerpkey PRIMARY KEY customerid
;
CREATE TABLE public.customeraddress
customerid int NOT NULL,
addressid int NOT NULL,
addresstype varchar NOT NULL,
modifieddate timestamp DEFAULT CURRENTTIMESTAMP NOT NULL,
CONSTRAINT customeraddresspk PRIMARY KEY customerid addressid, addresstype
;
ALTER TABLE public.customeraddress ADD CONSTRAINT customeraddresscfk FOREIGN KEY customerid REFERENCES public.customercustomerid;
ALTER TABLE public.customeraddress ADD CONSTRAINT customeraddressfk FOREIGN KEY addressid REFERENCES public.addressaddressid;
Add two materialized views productcountry Product should combine data of product and
its category. Country 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 typeaddresstype
Allow managers and administrators to read from these views.
Fields of product 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 'country 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
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