from my_functions import open_csvtest_db
from my_functions import close_database
from prettytable import PrettyTable

conn, cursor = open_csvtest_db()
sql = '''SELECT Embarked, COUNT(*), AVG(Fare), SUM(Fare) FROM titanic GROUP BY Embarked'''
cursor.execute(sql)
data = cursor.fetchall()
table2 = PrettyTable(['Embarked', 'Count', 'Average', 'Sum'])
for (embark, count, average, sum) in data:
    table2.add_row([embark, count, average, sum])
print(table2)
close_database(cursor, conn)