Analysing Book Store Sample Data with PostgreSQL
2 min read

Analysing Book Store Sample Data with PostgreSQL

Analysing Book Store Sample Data with PostgreSQL
Photo by John Barkiple / Unsplash

Writing complex SQL queries

Data model in Power BI

Requirements

The Product Owner needs  a daily report showing :

  • the order date
  • the number of orders for that date
  • the number of books ordered
  • the total price of the orders
  • the running total of books for the month
  • the number of books from the same day last week (e.g. how this Monday compares to last Monday)

An annual report showing :

  • year
  • the book title
  • the number of books sold
  • the total price of the orders

Customer History Report showing :

  • customer name
  • month - year
  • number of books purchased each month
  • monthly expenditure by customer

DAILY REPORT

PostgreSQL Query

Output

The first 17 rows of the output

I've created a status_updated view to filter the current status of the orders. So this view can be easily used in the following queries.

Creating View with PostgreSQL

ANNUAL REPORT

PostgreSQL Query

Output

The first 10 rows of the output

CUSTOMER HISTORY REPORT

Output

The first 10 rows of the output