使用LIKE搜索数据,其中参数为variab

2024-09-29 00:13:03 发布

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

我有一个sql数据库,其日期格式为DD/MM/YYYY和wat,用于搜索特定月份的所有数据,但使用LIKE?时出现错误?sqlite3.ProgrammingError:提供的绑定数量不正确。当前语句使用1,提供了8个。不知道该怎么做才能帮上忙

month=dt.datetime.now()
print(month.strftime('%m/%Y'))
month1='%'+month.strftime('%m/%Y')
print(month1)
with sqlite3.connect('The_database.db') as db2:
    find_date = db2.cursor()
    find_date.execute('select Dateandtime from Totaloverview where Dateandtime LIKE ?',(month1))
    date = find_date.fetchall()
    find_cost = db2.cursor()
    find_cost.execute('select costofitem from Totaloverview where Dateandtime LIKE ?',(month1))
    cost = find_cost.fetchall()

Tags: fromexecutedatefindselectsqlite3cursorlike