比如需要找出u_name中既有“三”又有“猫”的记录:
SQL原生语句如下:
SELECT * FROM [user] WHERE u_name LIKE '%三%' AND u_name LIKE '%猫%'
解决方案:
from sqlalchemy import and_
words = ['%三%', '%猫%'] rule = and_(*[table.u_name.like(w) for w in words]) table.query.filter(rule)
转载:https://segmentfault.com/q/1010000005681820