获取SQL查询以搜索多个列时出现问题

2024-04-20 01:56:44 发布

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

我需要我的SQL查询来搜索多个列,这是我目前所拥有的:

cur.execute("SELECT name, unit, phone1, phone2 FROM rdata WHERE lower(unit) LIKE lower(?) OR REPLACE(lower(name), ' ', '') LIKE REPLACE(lower(?), ' ', '')", [z.get(),])

我已经阅读了尽可能多的文档,但它仍然不起作用

我得到的错误是:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 2, and there are 1 supplied.


Tags: namefromexecutesqlunitwhereselectlower
1条回答
网友
1楼 · 发布于 2024-04-20 01:56:44

好的,多亏了你的帮助,我找到了答案。我增加了按电话号码搜索的功能,并改为按电话号码搜索

cur.execute('''SELECT name, unit, phone1, phone2 FROM rdata WHERE (lower(unit) LIKE lower(?))
                OR (REPLACE(lower(name), ' ', '') LIKE REPLACE(lower(?), ' ', ''))
                OR REPLACE(phone1, '-', '') LIKE REPLACE(?, '-', '')
                OR REPLACE(phone2, '-', '') LIKE REPLACE(?, '-', '')''',(z.get(), z.get(), z.get(), z.get()))

相关问题 更多 >