postgresql portfolio
TRANSCRIPT
![Page 1: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/1.jpg)
My PostgreSQL Portfolio
By: Michael J. Goodlett
![Page 2: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/2.jpg)
CREATE TABLE
![Page 3: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/3.jpg)
Next: Inserting Data
• Now that I have my columns created for the july_finances table, next I just insert the data into the necessary columns using a little creativity.
![Page 4: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/4.jpg)
Inserting The Data
![Page 5: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/5.jpg)
Table Results
• Now I can run SELECT * FROM july_finances to view all the data in the columns and rows of the table I just created.
![Page 6: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/6.jpg)
![Page 7: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/7.jpg)
Here is the remaining data. No need to worry about the values to the right as they are zero.
![Page 8: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/8.jpg)
As you can see I just subtracted the respective SUMs of John’s usd_income minus usd_spent. In addition, I identify this column as
money_left_over by simply adding AS money_left_over in the query.
![Page 9: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/9.jpg)
To compute John’s expected annual salary, given his monthly income remains the same, I ran the above query multiplying the sum of his
July usd_income by 12 and labeled the result as annual_income.
![Page 10: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/10.jpg)
Next: DVD Rental Company
• The following slides will include three new tables (Payment, Staff, & Film) from the database of a DVD rental company.
• I will use SQL queries to return specific types of information using these tables individually and in some scenarios I will incorporate the tables together.
![Page 11: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/11.jpg)
Payment Table Information
![Page 12: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/12.jpg)
Number of Rows – Payment Table
As you can see, the Payment table has exactly 14,596 rows of data.
![Page 13: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/13.jpg)
Staff Table Information
![Page 14: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/14.jpg)
Film Table Information
![Page 15: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/15.jpg)
Number of Rows – Film Table
As you can see, the Film table has a total of 1,000 rows of data.
![Page 16: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/16.jpg)
Joining the Payment & Staff Tables
In this scenario, I joined both tables to return the SUM of the transactions for each employee. This way, I can identify which employee has been the most productive regarding company sales.
![Page 17: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/17.jpg)
Sub-querying: Payment Table
By using the sub-querying method, I was able to return the customer_id (along with the amount) of each customer who spent the MAX amount of money during their respective transactions.
![Page 18: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/18.jpg)
Monthly Sales
By using the EXTRACT function with the timestamp data we have on all transactions, I was able to return the SUM of the amount for monthly sales.
![Page 19: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/19.jpg)
Sub-querying: Film Table
By using the sub-querying method, I was able to return specific information regarding the the titles of the movies which have the MAX rental_rate. I can also identify the years the movies were released along with the ratings and rental amounts.
![Page 20: PostgreSQL Portfolio](https://reader030.vdocuments.pub/reader030/viewer/2022021420/5886f0d51a28abba528b6afb/html5/thumbnails/20.jpg)
Conclusion
• The information returned with the SQL queries used in these projects can certainly be used to learn more specific information about the business, reveal the results of a marketing campaign, learn more about the customers & staff, and learn more about the products/services to ensure that better decisions are made based on the historical information we have about the business.