比如需要找出u_name中既有“三”又有“猫”的记录:SQL原生语句如下:
SELECT * FROM [user] WHERE u_name LIKE '%三%' AND u_name LIKE '%猫%'
请问这个如何在 SQLAlchemy 中实现呢
光阴似箭催人老,日月如移越少年。
from sqlalchemy import and_ words = ['%三%', '%猫%'] rule = and_(*[table.u_name.like(w) for w in words]) table.query.filter(rule)
DBSession().query(user).filter(user.u_name.like('%三%')).filter(user.u_name.like('%猫%'))
Or you can use and_()
and_()
DBSession().query(user).filter(and_(user.u_name.like('%三%'), user.u_name.like('%猫%')))
Or you can use
and_()