1.逻辑判断
1)逻辑或
from sqlalchemy import or_
User.query.filter(or_(User.mobile=='13911111111', User.name.endswith('号'))).all()
2)逻辑与
from sqlalchemy import and_
User.query.filter(and_(User.name != '13911111111', User.mobile.startswith('185'))).all()
3)逻辑非
from sqlalchemy import not_
User.query.filter(not_(User.mobile == '13911111111')).all()
2.条件
3.filter
1).filter_by
可以不用写对象名,但只能等值查询和AND查询
User.query.filter_by(mobile='13911111111').first()
2).filter需要写对象名
User.query.filter(User.mobile=='13911111111').first()
1.逻辑判断
1)逻辑或
from sqlalchemy import or_
User.query.filter(or_(User.mobile=='13911111111', User.name.endswith('号'))).all()
2)逻辑与
from sqlalchemy import and_
User.query.filter(and_(User.name != '13911111111', User.mobile.startswith('185'))).all()
3)逻辑非
from sqlalchemy import not_
User.query.filter(not_(User.mobile == '13911111111')).all()
2.条件
Name | Description |
---|---|
= | Equal operator |
<=> | NULL-safe equal to operator |
> | Greater than operator |
>= | Greater than or equal operator |
< | Less than operator |
<= | Less than or equal operator |
!=, <> | Not equal operator |
BETWEEN … AND … | 取非只要在前面加NOT就行 |
NOT BETWEEN … AND … | Whether a value is not within a range of values |
IN (value,...) | SELECT 2 IN (0,3,5,7)-> 0 ,另外,in用来where后的选择范围 |
NOT IN() | Whether a value is not within a set of values |
IS NOT NULL | NOT NULL value test |
IS NULL | NULL v |