mySQL正确的语法执行顺序(官方查询规则:https://dev.mysql.com/doc/refman/8.0/en/select.html)
#mysql例子:
SELECT DISTINCT * from gift WHERE launched=0 GROUP BY gift.isbn
#正确编写顺序...
select ... from... where.... group by... having... order by..
SQLachemy用函数的方式替换了这些语法规则,但是原理顺序和mysql是一样的(必须遵循一致性查询规则)
#SQLachemy的执行顺序(同mysql)
#select distinct(DISTINCT去重)----all(*最终查询的结果)
#from----filter_by(where)----group_by(分组)----order_by(排序)-----limit(显示条数)
def query_all_gift():
return Gift.query.filter_by(launched=False).group_by(Gift.isbn).order_by(
Gift.create_time).limit(30).distinct().all()
SQLachemy的查询Query函数大全去官方查找:https://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.limit