from dbconfig import * import pymysql import sys # Get command line argument of product line id. if len(sys.argv) > 1: pl_id = sys.argv[1] else: p1_id = 1 # Connect to big_pvfc of the MySQL server and # set up SQL statement to obtain product information # in the product line db = get_mysql_param() cnx = pymysql.connect(user=db['user'], password=db['password'], host=db['host'], database=db['database']) cursor = cnx.cursor() query = ''' select distinct p.productId, p.productDescription, p.ProductFinish, sum(o.OrderedQuantity) as `ordered` from product_t p join orderline_t o on (p.productId = o.productId) where p.ProductLineID = %s group by p.productId, p.productDescription, p.ProductFinish; ''' cursor.execute(query,(int(pl_id),)) # Print product report. print('Products in Line #' + str(pl_id) + ':') print('--------------------') for (pid, desc, finish, ordered) in cursor: print('[' + desc + ' (id #' + str(pid) + '), finish: ' + finish + ']:' + str(ordered) + ' ordered.') cursor.close() cnx.close()