# %a%:匹配数据中心包含a字符的数据
# like:主要用于匹配数据库中的多条记录
# a_:匹配以a开头,并且只匹配a最后一个字符的数据。
# %a:匹配以a结尾的数据
# a%:匹配以a开头的数据
# %a%:匹配数据中心包含a字符的数据
import sqlite3
# 1. 创建数据库连接
connect = sqlite3.connect('sqltest.db')
# 2. 使用连接创建游标
cursor = connect.cursor()
# 查找student表中age大于22的数据
sq = "select * from student where age >22"
# 查找student表中name=‘王思聪’的数据
sql_4 = "select * from student where name='王思聪'"
# 查找student表中name以‘三’结尾的数据
sql_1 = "select * from student where name like '%三'"
# 查找student表中name以‘王’开头的数据
sql_2 = "select * from student where name like '王%'"
# 查找student表中name中间包含‘思’的数据
sql_3 = "select * from student where name like '%思%'"
result = cursor.execute(sql_4)
for id,name,age,score in result:
print(id,name,age,score)
# 提交操作
connect.commit()
# 关闭游标
cursor.close()
# 关闭数据库连接
connect.close()