本帖最后由 thepoy 于 2020-7-15 22:09 编辑
变量起名时要科学啊,你这种代码,看一眼就懒得看第二眼。等过两天,你自己写的代码自己都看不懂了。
result12 = cursor.execute('select count(id) from dr') # dr表中数据的数量
kn = result12.fetchone()
kb = kn[0] # dr表中数据的数量
xx1 = cursor.execute("select number from dr") # dr表中取中所有的number字段,上面的result12 = cursor.execute('select count(id) from dr')就属于重复代码了吧,因为数量不就是len(xx2)吗?而且查找表中数量总量最好用count(*),不要count(字段名)
xx2 = xx1.fetchall()
for i in range(0, kb):
xx13 = str(xx2[i][0])
print(xx13)
xx3 = cursor.execute('select * from back where number = ?', [xx13])
xx6 = xx3.fetchone()
print(xx6)
if xx6 == None: # 如果back表中没有xx13,就在dr中删除此条数据?这是你想要的结果吗?
cursor.execute("delete from dr where number = ?",[xx13])
conn.commit() # commit()为什么要放在这里?
|