比如需要找出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
