错误:列表索引超出范围。Python变量是使用当前fetchall()没有从一个SQL查询读入另一个SQL查询

2024-04-19 08:46:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我从一个SQL查询中得到一个值,它以max\u dateCS的名称存储。此变量需要输入到另一个SQL查询中。我面临这样做的问题,因为它会给出一个错误'列表索引超出范围'。你知道吗

query2 = """select max(date_hour) from mu_test_table1"""

cur.execute(query2);

conn.commit()

max_dateCS = cur.fetchall();

 Query3= """select count (*) from mu_test_table1
 where date_hour = %s;"""

cur.execute(Query3,(max_dateCS[0]));
conn.commit()
rows = cur.fetchall();

Tags: fromtestexecutesqldateconnselectmax