I am trying to get the column names to print for my code below, it only prints the results of the queries, the results being underneath each other.
Is there a way to append the column names above each query result? Or is there a way to append custom column names about each result?
cur = db.cursor()
cur = db2.cursor()
cur = db3.cursor()
#SQL Queries
dbQuery="SELECT COUNT(DISTINCT Name) FROM blah;"
dbQuery2="SELECT COUNT(Pause) FROM blah WHERE Pause = 1;"
dbQuery3="SELECT COUNT(Pause) FROM blah WHERE Pause = 0;"
result = []
cur.execute(dbQuery)
result.extend(cur.fetchall())
cur.execute(dbQuery2)
result.extend(cur.fetchall())
cur.execute(dbQuery3)
result.extend(cur.fetchall())
column_names = [i[0] for i in cur.description]
fp = open('Result_Set.csv', 'w')
myFile = csv.writer(fp)
myFile.writerow(column_names)
myFile.writerows(result)
fp.close()
I feel as though I am missing something simple.
Any help would be greatly appreciated
Thanks