V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
coolair
V2EX  ›  问与答

请教一个 SQLAlchemy 连接 subquery 的写法

  •  
  •   coolair · Apr 10, 2019 · 913 views
    This topic created in 2580 days ago, the information mentioned may be changed or developed.
    member_query = db.session.query(func.count(Member.id).label('member'), extract('year', Member.created_at).label('year')).group_by('year').subquery()
    order_query = db.session.query(func.count(Order.id).label('order'), extract('year', Order.created_at).label('year')).group_by('year').subquery()
    product_query = db.session.query(func.count(Product.id).label('product'), extract('year', Product.created_at).label('year')).group_by('year').subquery()
    

    现在想把这些 subquery 连接起来得到下面样的数据:

    结果

    应该怎么写?谢谢。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   807 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:40 · PVG 03:40 · LAX 12:40 · JFK 15:40
    ♥ Do have faith in what you're doing.