#!/usr/bin/env python #encoding:utf-8 import MySQLdb tell_file='/home/test/liyiliang/study/tell.info' f = file(tell_file) account_list = f.readlines() f.close() for n in account_list: h=n.strip().split() name = h[0] phone = h[1] try: conn = MySQLdb.connect(host='x.x.x.x',user='xxxx',passwd='xxxxxxx',port=xxxxx,charset='utf8') cur = conn.cursor() cur.execute('select promotioncode from cinf_db.cinf_promotioncode where mp = %s',phone) mycode = cur.fetchall() numTwo=0 for code in mycode: cur.execute('select mp from cinf_db.cinf_promotioncode_reward_history where reward_type=1 and promotioncode = %s',code) op = cur.fetchall() cur.execute('select count(*) from cinf_db.cinf_promotioncode_reward_history where reward_type=1 and promotioncode= %s ',code) mynum = cur.fetchall() for opnum in op: cur.execute('select promotioncode from cinf_db.cinf_promotioncode where mp = %s',opnum) othercode = cur.fetchall() for oc in othercode: cur.execute('select count(*) from cinf_db.cinf_promotioncode_reward_history where reward_type=1 and promotioncode = %s',oc) everone = cur.fetchall() for a in everone: b=int(a[0]) numTwo += b for numOne in mynum: print '%s' %name, print '%s' %phone, print '%s' %numOne, print '%s' %numTwo cur.close() conn.close() except MySQLdb.Error,e: print "MySQLdb Error",e
本文出自 “Chocolee” 博客,谢绝转载!