尝试执行匹配4个变量的选择查询,其中一个变量检查标题中的字符串。如何使用python游标类执行LIKE语句?或另一种方式?
["urn:ietf:wg:oauth:2.0:oob","http://localhost"]
编辑:表架构
stmt = "SELECT * FROM publication NATURAL JOIN journal NATURAL JOIN authors WHERE name = ? AND year = ? AND booktitle = ? AND title LIKE '%%%s%%'" % (input_names, input_year, input_booktitle, input_string)
print(stmt)
cur.execute(stmt)
答案 0 :(得分:1)
我认为真正的问题是你正在加入,你不会告诉它从哪里取列(从哪个表)。
你可以尝试添加表格吗? 我不确定它会有所帮助,但让我们试试(因为也许你们在这些表中没有相同的列名) 是那样的?stmt = "SELECT * FROM publication NATURAL JOIN journal NATURAL JOIN
authors WHERE authors.name = ? AND journal.year = ? AND
journal.booktitle = ? AND journal.title LIKE
'%%%s%%'" % (input_names, input_year, input_booktitle, input_string)
print(stmt)
cur.execute(stmt)
第二件事: 你应该使用'%s'而不是'?'
stmt = "SELECT * FROM publication NATURAL JOIN journal NATURAL JOIN
authors WHERE authors.name = '%s' AND journal.year = '%s' AND
journal.booktitle = '%s' AND journal.title LIKE
'%%%s%%'" % (input_names, input_year, input_booktitle, input_string)
print(stmt)
cur.execute(stmt)