1、参考:https://blog.csdn.net/nongcunqq/article/details/120220247
https://docs.sqlalchemy.org/en/14/orm/query.html
2、代码示例:
db.session.query(Test).with_entities(Test.Name,Test.Age).distinct().all()
3、分页去重代码示例:
pagination = db.session.query(distinct(remake.ITEMID)) \
.filter(or_(Remark.INS_TIME.is_(None),
Remark.INS_TIME < end_date
)) \
.with_entities(distinct(Remark.ITEMID).label('ITEMID')) \
.order_by(Remark.ITEMID.asc()) \
.paginate(page=1, per_page=50, error_out=False)
或者:
pagination = db.session.query(Remark) \
.filter(or_(Remark.INS_TIME.is_(None),
Remark.INS_TIME < end_date
)) \
.with_entities(Remark.ITEMID).distinct() \
.order_by(Remark.ITEMID.asc()) \
.paginate(page=1, per_page=50, error_out=False)