Question: Hello! Help with SQL , please! We have following tables from database _ _ adventureworkslt: CREATE TABLE public.customer ( customerid int 4 NOT NULL, namestyle

Hello! Help with SQL, please!
We have following tables from database __adventureworkslt:
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);
CREATE TABLE public.address (
addressid serial4 NOT NULL,
addressline1 varchar(60) NOT NULL,
addressline2 varchar(60) NULL,
city varchar(30) NOT NULL,
postalcode varchar(15) NOT NULL,
spatiallocation varchar(44) NULL,
stateprovinceid int4 NOT NULL,
countryregioncode varchar(3) NOT NULL,
isonlystateprovinceflag bool NOT NULL,
stateprovincename varchar(50) NOT NULL,
territoryid serial4 NOT NULL,
territoryname varchar(50) NOT NULL,
CONSTRAINT address_pkey PRIMARY KEY (addressid)
);
CREATE TABLE company (
id int4 NOT NULL GENERATED ALWAYS AS IDENTITY,
cname varchar(200) NOT NULL,
countrycode varchar(10) NULL,
city varchar(30) NULL,
CONSTRAINT d_company_pk PRIMARY KEY (id)
);
In the current database the customer table contains information about two categories of buyers -
individuals and companies. However, we consider only companies. For the convenience of further
development, fill the company table with data.
Data from the companyname field should be included in the list of companies. The country and the
city should be taken from the address table. Develop a query to load the country table.
Follow these rules in the table below. Use an addresses of Main Office type to find the appropriate
information.
Field Description Rule
--------------------------------------------
id |Company key | Auto-g|enerated value. No need to populate it manually
cname | Company name |Company name customer.companyname
countrycode | Code of country |Head office country address.countryregioncode
city | City name | Head office city address.city
The following tables can be used to form the company table: customer, customeraddress, address.

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!