I need help to have my results show as amount, amount_discounted and month in a table. I was able to do it in MySQL workbench but not through Python. Here is my code.
#! /usr/bin/env python
# Importing connector
import mysql.connector
conn = None
#Opening a connection
try:
conn = mysql.connector.Connect(host="localhost", user="root",password="Karimanzira1978!", database="classicmodels")
print("Connected to MySQL!")
except Exception as ex:
print ("cannot connect to MySQL : exception : " + str(ex))
# Setting a cursor
cursor1 = conn.cursor()
cursor2= conn.cursor()
c = conn.cursor()
cursor1.execute("SELECT sum(amount), sum(amount *.99) as discounted_amount, paymentDate from payments where paymentDate >= '2003-12-01' AND paymentDate <='2003-12-31'")
print(cursor2.fetchall())
cursor2.execute("SELECT sum(amount), sum(amount *.99) as discounted_amount, paymentDate from payments where paymentDate >= '2004-12-01' AND paymentDate <='2004-12-31'")
print(cursor2.fetchall())
conn.commit()
conn.close