如何删除table中的多行?使用单个代码,无需在内部输入两次执行和条件

How to delete more than one row in a table? Using a single code, without two times typing execute and conditions inside

import sqlite3
conn = sqlite3.connect('example.db') # connectiong to database or creating new if table does 
not exist
cursor = conn.cursor() # allows python to use sql commands

cursor.execute('''CREATE TABLE IF NOT EXISTS Fruits( #creating table
code TEXT PRIMARY KEY, # text data-type, primary key -constraint
name TEXT,
price FLOAT);
''')
conn.commit() # saves all changes made
fruit_list = [('1','blackberry', 300.00),('2','raspberry', 250.00), ('3','bananas', 150.00), 
('4','strawberry', 200.00)] #list of tuples
cursor.executemany('INSERT INTO Fruits VALUES(?,?,?)', fruit_list) # inserting data into table

cursor.execute("""从名称='blackberry'"""的水果中删除") cursor.execute("""从价格='150.00'的水果中删除""" )

cursor.execute('SELECT * FROM Fruits')
show_all = cursor.fetchall()
for e in show_all:
print('code: {} | name: {} | price {}'.format(e[0],e[1],e[2]))

您可以将 WHERE 子句中的所有条件与逻辑运算符 OR 组合在一个语句中:

DELETE 
FROM Fruits 
WHERE name='blackberry' OR price='150.00'