如何在 LIKE 查询 SQLite 中将 % 与输入变量一起使用?
How do I use % with input variable in LIKE query, SQLite?
我正在使用以下代码分配一个变量作为输入以识别具有特定结尾的记录,但它不起作用...请帮忙!
import sqlite3
connection = sqlite3.connect("music.db")
cursor = connection.cursor()
publisher_ends_with = input("Enter the ending: ")
ending_search = cursor.execute('''SELECT Publisher, COUNT(Publisher) FROM BL_music_records WHERE Publisher LIKE ?''', ('%’ publisher_ends_with,)).fetchall()
LIKE 语句的值格式不正确:
import sqlite3
connection = sqlite3.connect("music.db")
cursor = connection.cursor()
publisher_ends_with = input("Enter the ending: ")
ending_search = cursor.execute('''
SELECT Publisher FROM BL_music_records WHERE Publisher LIKE ?
''', (f'%{publisher_ends_with}',))
ending_search_results = ending_search.fetchall()
for row in ending_search_results:
print(row)
我正在使用以下代码分配一个变量作为输入以识别具有特定结尾的记录,但它不起作用...请帮忙!
import sqlite3
connection = sqlite3.connect("music.db")
cursor = connection.cursor()
publisher_ends_with = input("Enter the ending: ")
ending_search = cursor.execute('''SELECT Publisher, COUNT(Publisher) FROM BL_music_records WHERE Publisher LIKE ?''', ('%’ publisher_ends_with,)).fetchall()
LIKE 语句的值格式不正确:
import sqlite3
connection = sqlite3.connect("music.db")
cursor = connection.cursor()
publisher_ends_with = input("Enter the ending: ")
ending_search = cursor.execute('''
SELECT Publisher FROM BL_music_records WHERE Publisher LIKE ?
''', (f'%{publisher_ends_with}',))
ending_search_results = ending_search.fetchall()
for row in ending_search_results:
print(row)