发布于 5个月前

mysql 数据库 删除两个表之间的差集

sql= '''

select Novel_name from(select Novel_name from %s GROUP BY Novel_name ORDER BY Novel_ID ASC)as t where Novel_namenot in(select TXT_name from %s);

''' %(j,i)

sql='''

DELETE FROM %s WHERE Novel_pid = any(

SELECT Novel_pid FROM(SELECT Novel_pid FROM %s GROUP BY Novel_pid) as cu left join %s as cm on Novel_pid= TXT_ID where TXT_ID is NULL);

'''%(j,j,i)

cursor.execute(sql)

NoveID_list= cursor.fetchall()

print(NoveID_list)

print(len(NoveID_list))


flag= False

while not flag:

try:

# for line in readfile(txt_path + "8.txt")[322:]: # (323) 858

# line = line.split("\t")

# Novel_pid = line[0]

# Novel_name = line[1]

# print(Novel_pid,Novel_name)

db= pymysql.connect('27.255.79.21','user','*****!','db_qishu',charset="utf8")

cursor= db.cursor()

#sql = "select Novel_ID from qishu\_books\_sort08 WHERE Novel_pid = %s;"%Novel_pid

sql= "select Novel_ID from qishu\_books\_sort08 WHERE Novel_pid = 323;"

cursor.execute(sql)

Novel_list= cursor.fetchall()

print(len(Novel_list))

i= 0

for Novel_IDin Novel_list:

Novel_ID= Novel_ID[0]

print(Novel_ID,str(i))

i+= 1

sql= "UPDATE qishu_books_sort08 SET Novel_ID_Count = %s WHERE Novel_ID = %s"%(i,Novel_ID)

cursor.execute(sql)

db.commit()

except Exception as ex:

print(Exception,":", ex)

flag= True

©2020 edoou.com   京ICP备16001874号-3