wangyueyong1
lokewang
2017-08-31 10:21
采纳率: 100%
浏览 4.4k

python flask 框架多表连接查询

sql语句是这样的,不熟悉SQLAlchemy 不知道该怎么写,求大神帮助
SELECT A.project_id,A.creator,A.ip,B.auto_id,B.argument,B.status,B.reportlink,B.taskid
FROM (
SELECT project_id,creator,ip
FROM application
WHERE project_id IN (25696)
)
A
LEFT OUTER JOIN
auto_test
B ON A.project_id = B.project_id;

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • sczhoubing
    sczhoubing 2017-09-02 06:35
    已采纳
    sql_data =  db.session().query(application,auto_test )
    sql_data = sql_data.join(auto_test, application.project_id == auto_test.project_id)
    sql_data = sql_data.filter(
        func.find_in_set("25696", application.project_id) 
    ).all
    

    你试试看呢,方法如此,auto_test, application是定义的model名称

    点赞 评论

相关推荐