import pymysql
conn = pymysql.connect(host=‘10.1.2.198‘, port= 3306 ,user=‘root‘,passwd=‘123456‘,db=‘testing‘)
cur = conn.cursor()
#获取与CUSTOMER_ID交易总额最大的客户NAME
sql="select CUSTOMER_ID,NAME,TRADE_AMOUNT from tm_trade where TRADE_AMOUNT=(SELECT MAX(TRADE_AMOUNT) FROM tm_trade)"
cur.execute(sql)
# 获取所有记录列表
results = cur.fetchall()
for row in results:
print(‘************‘,row,‘\n‘)
company_ID=row[0]
trade_name = row[1]
conn.commit()
cur.close()
conn.close()
时间: 2024-10-09 08:39:11