Create a view Q1 that appends the country and region name to
Create a view Q1 that appends the country and region name to each customer. Rewrite Q1 from Lab4 with view Q1.
This is the query from lab 4
select avg(o_totalprice), c_name
from nation, customer, orders
where n_nationkey = c_nationkey
and c_custkey = o_custkey
and n_name = \'BRAZIL\'
group by c_custkey
please help, I did not understand what it meant to append country and region name to customer
Solution
A view always shows up-to-date data.we can create a view by using the below syntax
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
Here we need to append country and region name to customer,that means we need to concat Country and Region name to customer column.
the below view concats /appends country and region as \"country_region_cname\" for each customer
let us discuss with simple example.customer table
Nation table
based on our view we will get the below table
| custId | CustName |
| 001 | John |
| 008 | Paul |
