【问题标题】:FULL JOIN in SQLAlchemy?完全加入 SQLAlchemy?
【发布时间】:2011-06-06 04:25:03
【问题描述】:

我想在预算应用程序中显示“最后条目”列表。条目(如费用、收入、账户转账、贷款)具有除 user_id 之外定义的不同列。

在 SQL 中,我会选择 FULL JOIN,但我使用的是 SQLAlchemy(声明式)。这里的正确方法是什么?一些元表?

非常感谢。

示例表:

class Expense(Base):
    __tablename__ = 'expenses'
    id = Column(Integer, primary_key=True)
    user = Column('user_id', Integer, ForeignKey('users.id'))
    date = Column(Integer)
    category = Column('category_id', Integer, ForeignKey('expense_categories.id'))
    description = Column(String(50))
    deduct_from = Column('account_id', Integer, ForeignKey('accounts.id'))
    amount = Column(Float(precision=2))

class Loan(Base):
    __tablename__ = 'loans'
    id = Column(Integer, primary_key=True)
    from_user = Column('from_user_id', Integer, ForeignKey('users.id'))
    to_user = Column('to_user_id', Integer, ForeignKey('users.id'))
    date = Column(Integer)
    account = Column('account_id', Integer, ForeignKey('accounts.id'))
    description = Column(String(50))
    amount = Column(Float(precision=2)

【问题讨论】:

    标签: python sql sqlalchemy flask


    【解决方案1】:

    如果您的数据库支持,您必须使用raw SQL,否则必须使用union。来自http://groups.google.com/group/sqlalchemy/msg/80ea8e712380bff4

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 2015-04-07
    • 2013-09-24
    • 2014-12-27
    相关资源
    最近更新 更多