本站资源收集于互联网,不提供软件存储服务,每天免费更新优质的软件以及学习资源!

如何在Orator中使用多个LIKE查询?

网络教程 app 1℃

如何在Orator中使用多个LIKE查询

如何在 python 的 orator 中构建多个 like 查询?

原生 sql 语句支持使用 or 运算符将多个 like 查询条件组合在一起,例如:

select * from `think_user` where (`name` like ‘%think%’ or `name` like ‘%php%’)

要将此查询转换为 orator,可以使用多次赋值方法:

and 逻辑:

# 实现 and 逻辑search = [‘%word1%’, ‘%word2%’, ‘%word3%’, …]info = db.table(‘full_text’)for s in search: info = info.where(‘title’, ‘like’, s)result = info.get()

or 逻辑:

# 实现 OR 逻辑search = [‘%word1%’, ‘%word2%’, ‘%word3%’, …]info = DB.table(‘full_text’)for s in search: if search.index(s) == 0: info = info.where(‘title’, ‘like’, s) else: info = info.or_where(‘title’, ‘like’, s)result = info.get()

需要特别注意的是,与原生 sql 语句不同,orator 的 like 查询使用通配符 % 包裹搜索词,而不是使用百分号占位符。

以上就是如何在 Orator 中使用多个 LIKE 查询?的详细内容,更多请关注范的资源库其它相关文章!

转载请注明:范的资源库 » 如何在Orator中使用多个LIKE查询?

喜欢 (0)