"""
Following the Dataquest tutorial:
https://www.dataquest.io/blog/sql-basics/
"""
import sqlite3
import pandas as pd
# Python needs to connect to the database and the connection should be closed at some point
db = sqlite3.connect(r"c:\SQLite\hubway.db")
def run_query(query):
return pd.read_sql_query(query,db)
query = 'SELECT * FROM trips LIMIT 5;' # * is a wildcard and will return all the column, but only 5 rows
run_query(query)
# Counting the number of rows in the Trips table, where there are Registered users, with AS a new column title can be given to the query answer
query = 'SELECT COUNT(*) AS "Total Trips by Registered Users" FROM trips WHERE sub_type = "Registered";'
run_query(query)