Skip to content

beardofedu/python-sql-exercise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

Python / SQL Exercise

This repository contains the files to run tests against an existing PostgreSQL database.

For an example of an output of the reportGen.py file, click here

Running the script

The reportGen.py file utilizes three queries to generate reports for the following three questions:

  1. What are the most popular three articles of all time? topArticles.sql
  2. Who are the most popular article authors of all time? topAuthors.sql
  3. On which days did more than 1% of requests lead to errors? totalErrors.sql

NOTE: Before running the reportGen.py file, there are some required views. NOTE: Modify the reportGen.py file with your user and password.

Views Needed

The python script expects the following views to exist within the database:

vw_httpStatusError

CREATEVIEWvw_httpStatusErrorASSELECTcount(*), status, DATE(TIME), SUBSTRING(status, 1, 3) as httpStatus FROM log WHERE status ='404 NOT FOUND'GROUP BY status, DATE(TIME) ORDER BYDATE(TIME)

vw_httpStatusOK

CREATEVIEWvw_httpStatusOKASSELECTcount(*), status, DATE(TIME), SUBSTRING(status, 1, 3) as httpStatus FROM log WHERE status ='200 OK'GROUP BY status, DATE(TIME) ORDER BYDATE(TIME)

vw_topArticles

CREATEVIEWvw_topArticlesASSELECT DISTINCTcount(*), A.title, FORMAT('"%s" - %s views', A.title, count(*)) AS POPULAR FROM log l INNER JOIN articles A ONSUBSTRING(l.path, 10, 100) =A.SLUGGROUP BYA.titleORDER BYcount(*) descLIMIT3

vw_topAuthors

CREATEVIEWvw_topAuthorsASSELECT DISTINCTcount(*), AU.name, FORMAT('%s - %s views', AU.name, count(*)) AS POPULAR FROM log l INNER JOIN articles A ONSUBSTRING(l.path, 10, 100) =A.SLUGINNER JOIN Authors AU ONAU.ID=A.authorGROUP BYAU.nameORDER BYcount(*) desc

About

A repository for a project using Python and SQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages