Topic: Challenge Set 9 Part III
Subject: SQL
Date: 02/20/2017
Name: Prashant Tatineni
In [2]:
import sqlite3
In [3]:
db = sqlite3.connect('database.sqlite')
In [5]:
cursor = db.cursor()
In [8]:
cursor.execute("select name from sqlite_master where type='table'")
Out[8]:
In [9]:
print(cursor.fetchall())
In [11]:
cursor.execute("select * from Player_attributes limit 10;")
print(cursor.fetchall())
1. Which team scored the most points when playing at home?
In [ ]:
In [ ]:
In [ ]:
2. Did this team also score the most points when playing away?
In [ ]:
In [ ]:
In [ ]:
In [ ]:
3. How many matches resulted in a tie?
In [ ]:
In [ ]:
In [ ]:
In [ ]:
4. How many players have Smith for their last name? How many have 'smith' anywhere in their name?
In [ ]:
In [ ]:
In [ ]:
In [ ]:
5. What was the median tie score? Use the value determined in the previous question for the number of tie games. Hint: PostgreSQL does not have a median function. Instead, think about the steps required to calculate a median and use the WITH command to store stepwise results as a table and then operate on these results.
In [ ]:
In [ ]:
In [ ]:
6. What percentage of players prefer their left or right foot? Hint: Calculate either the right or left foot, whichever is easier based on how you setup the problem.
In [ ]:
In [ ]:
In [ ]: