2 wangyueyong1 wangyueyong1 于 2017.08.31 18:21 提问

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 14: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名称

Csdn user default icon
上传中...
上传图片
插入图片