V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Fiery123
V2EX  ›  Python

Flask-Sqlalchemy 查询最大值

  •  
  •   Fiery123 · 2018-12-24 18:08:18 +08:00 · 3801 次点击
    这是一个创建于 1922 天前的主题,其中的信息可能已经有所发展或是发生改变。
    请教下 Flask-Sqlalchemy 查询最大值是怎么写? Sqlalchemy 是 func.max FlaskSqlalchemy 没有看到相关的语法。
    4 条回复    2018-12-25 11:09:10 +08:00
    autotesting
        1
    autotesting  
       2018-12-24 18:56:09 +08:00
    groupby 后才能用 func.max, func.min 这样
    Fiery123
        2
    Fiery123  
    OP
       2018-12-24 19:12:17 +08:00
    @autotesting 有参考的例子吗,,现在我的方法是执行原始 sql 语句
    autotesting
        3
    autotesting  
       2018-12-24 22:42:09 +08:00
    其实很多,https://stackoverflow.com/questions/45775724/sqlalchemy-group-by-and-return-max-date
    你搜关键词 sqlachemy groupby func.max
    Fiery123
        4
    Fiery123  
    OP
       2018-12-25 11:09:10 +08:00
    @autotesting 我用这样的语法查出来为空
    userbalance_model.query.filter_by(user_id = parse.user_id, asset = parse.coin).with_entities(func.max(userbalance_model.id)).all()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2892 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:17 · PVG 22:17 · LAX 07:17 · JFK 10:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.