Exercise 6.2 - Customers:
In pg-admin, create a SQL script that does the following:
Tables:
Customers. Alias ascuSales_Header. Alias asshSales_Detail. Alias assd
Attributes:
customer_name. Alias ascustomer- Most recent
date_sale. Alias asmost_recent- HINT: Use the
MAXaggregator for this
- HINT: Use the
- Count the number of
sale_ids for that customer. Alias astransactions - Average
revenuefor that customer rounded to 1 decimal place. Alias asavg_spend - Average number of
items_soldrounded to 1 decimal place. Alias asavg_items - Average
feedback_scorerounded to 1 decimal place. Alias asavg_feedback
Other considerations:
- Order by
average revenuewith the highest value first - Limit the output to the first 10 rows only
-
Test this script in PostgreSQL
- The names and data should match the screenshot
-
Convert this SQL script into a
VIEWcalledv_Top_Customers -
Append SQL to
SELECT * FROMthisVIEWinto the space provided in line 13 of backend/routes/customers.js -
Save and close backend/routes/customers.js
You may need to close and re-run your Docker session for this to take effect
- In a new browser tab, preview the transactions route (http://localhost:5001/customers)
- This should be populated with an array of 10 objects for each customer
- This is the data that our front-end will use to populate the Customers table on the web page
- In the main Sequel-Mark website (http://localhost:5001), check the Customers table has been populated