Docsity

WGU D191 VDM Task 1 – Automating Data Integration, Exams of Nursing

Partial preview of the text

Download WGU D191 VDM Task 1 – Automating Data Integration and more Exams Nursing in PDF only on Docsity!

Advanced Data Management (D191) – Automating

Data Integration – Task 1

SECTION A

In this business report, I will identify the top three most watched movies along with the revenue generated by each of those movies. This could be useful to see the most popular movies, how much revenue each one creates, and if you might want to increase the price based on supply and demand. This could also tell you if it might be wise to increase your inventory of those specific movies.

  1. Describe the data used for the report. A. The film id was counted based on the rental id to see how many times each movie was rented. Then it was grouped by the film id and ordered by count descending. Then the top three was chosen with the limit three. Then the sum of the payment amount was found for each.
  2. Identify two or more specific tables from the given dataset that will provide the data necessary for the detailed and the summary sections of the report. A. The tables that were used to generate this report was: rental, inventory, film and payment.
  3. Identify the specific fields that will be included in the detailed and the summary sections of the report. A. The data needed for this report was rental id, inventory id, film id, film title more for visual, and payment amount. The film id was counted based on the rental id to see how many times each movie was rented. Then it was grouped by the film id and ordered by count descending. Then the top three was chosen with the limit three. Then the sum of the payment amount was found for each.
  4. Identify one field in the detailed section that will require a custom transformation and explain why it should be transformed. For example, you might translate a field with a value of ‘N’ to ‘No’ and ‘Y’ to ‘Yes’. A. The transformed data was the payment amount of the summary table. It was aggregated to find the total amount of revenue generated for each of the top three movies. But did write a ‘SELECT’ statement that would pull the data and change the ‘amount’ column from a numeric to money using the CASE function for ease of reading; to distinguish from all the generic numbers within the table. B. In the detailed section, it is raw data and no reason to transform any data as of yet in the process. The transformation would take place in the summary section.
  5. Explain the different business uses of the detailed and the summary sections of the report. A. This could be useful to see the most popular movies, how much revenue each one creates, and if you might want to increase the price based on supply and demand. This could also tell you if it might be wise to increase your inventory of those specific movies. Help monitor consumer trends to assist in delivering similar movies which will improve the customer experience. This could especially be useful to increase traffic/business.
  6. Explain how frequently your report should be refreshed to remain relevant to stakeholders. A. This report could possibly be ran once a month to give a good idea of what movies are popular at that moment in time and the revenue generated. But would expect to be based on the volume of the store.

SECTION B

Write a SQL code that creates the tables to hold your report sections. --Create detailed Table DROP TABLE IF EXISTS detailed;

CREATE OR REPLACE FUNCTION top3_rentals() RETURNS TRIGGER AS $$ BEGIN DELETE FROM summary; INSERT INTO summary( SELECT COUNT(film_id) AS rental_cnt, film_id, title, CAST(SUM(amount) AS money) AS rental_rev FROM detailed GROUP BY film_id, title ORDER BY rental_cnt DESC LIMIT 3); RETURN NEW; END; $$ LANGUAGE PLPGSQL; SELECT * FROM summary;

SECTION E

Write a SQL code that creates a trigger on the detailed table of the report that will continually update the summary table as data is added to the detailed table. --Create Trigger CREATE TRIGGER film_rentals AFTER INSERT ON detailed FOR EACH STATEMENT EXECUTE PROCEDURE top3_rentals();

SECTION F

Create a stored procedure that can be used to refresh the data in both your detailed and summary tables. The procedure should clear the contents of the detailed and summary tables and perform the ETL load process from part C and include comments that identify how often the stored procedure should be executed. --Creating Procedure CREATE OR REPLACE PROCEDURE refresh() LANGUAGE PLPGSQL AS $$ BEGIN DELETE FROM detailed; INSERT INTO detailed( rental_id, inventory_id, film_id,

title, amount ) SELECT r.rental_id, i.inventory_id, f.film_id, f.title, CAST(p.amount AS money FROM payment p INNER JOIN rental r ON r.rental_id = p.rental_id INNER JOIN inventory i ON i.inventory_id = r.inventory_id INNER JOIN film f ON f.film_id = i.film_id; END; $$; --This procedure should be ran once a month

  1. Explain how the stored procedure can be run on a schedule to ensure data freshness. A stored procedure could be scheduled to run on a schedule setup within pgAdmin. This could be setup to run once a month as indicated at the beginning of this report to ensure data is accurate to be able to make sound business decisions.

SELECT

r.rental_id, i.inventory_id, f.film_id, f.title, p.amount FROM payment p INNER JOIN rental r ON r.rental_id = p.rental_id INNER JOIN inventory i ON i.inventory_id = r.inventory_id INNER JOIN film f ON f.film_id = i.film_id; --CREATING FUNCTION CREATE OR REPLACE FUNCTION top3_rentals() RETURNS TRIGGER AS $$ BEGIN DELETE FROM summary; INSERT INTO summary( SELECT COUNT(film_id) AS rental_cnt, film_id, title, SUM(amount) AS rental_rev FROM detailed GROUP BY film_id, title ORDER BY rental_cnt DESC LIMIT 3); RETURN NEW; END; $$ LANGUAGE PLPGSQL; SELECT * FROM summary; --Create Trigger CREATE TRIGGER film_rentals AFTER INSERT ON detailed FOR EACH STATEMENT EXECUTE PROCEDURE top3_rentals(); --Creating Procedure CREATE OR REPLACE PROCEDURE refresh() LANGUAGE PLPGSQL AS $$ BEGIN DELETE FROM detailed; INSERT INTO detailed( rental_id, inventory_id, film_id, title, amount ) SELECT r.rental_id, i.inventory_id,

f.film_id, f.title, p.amount FROM payment p INNER JOIN rental r ON r.rental_id = p.rental_id INNER JOIN inventory i ON i.inventory_id = r.inventory_id INNER JOIN film f ON f.film_id = i.film_id; END; $$; CALL refresh(); SELECT * FROM detailed; SELECT rental_id, inventory_id, film_id, title, amount::money FROM detailed; SELECT * FROM summary; Link to recording: https://wgu.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=3a35fa43-35d1-4e65-8c53- af940172efbd# REFERENCES:

  1. https://www.postgresqltutorial.com/