postgresql portfolio

20
My PostgreSQL Portfolio By: Michael J. Goodlett

Upload: michael-j-goodlett

Post on 14-Apr-2017

58 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PostgreSQL Portfolio

My PostgreSQL Portfolio

By: Michael J. Goodlett

Page 2: PostgreSQL Portfolio

CREATE TABLE

Page 3: PostgreSQL Portfolio

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

Inserting The Data

Page 5: PostgreSQL Portfolio

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
Page 7: PostgreSQL Portfolio

Here is the remaining data. No need to worry about the values to the right as they are zero.

Page 8: PostgreSQL Portfolio

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

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

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

Payment Table Information

Page 12: PostgreSQL Portfolio

Number of Rows – Payment Table

As you can see, the Payment table has exactly 14,596 rows of data.

Page 13: PostgreSQL Portfolio

Staff Table Information

Page 14: PostgreSQL Portfolio

Film Table Information

Page 15: PostgreSQL Portfolio

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

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

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

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

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

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.