sql = "SELECT batch,start_time,end_time " \
"from repair_order_table " \
"WHERE batch = (" \
"SELECT batch FROM repair_order_table WHERE line=:line ORDER BY start_time DESC LIMIT 1") and line=:line;"
batch_res = db.session.execute(sql, {"line": line}).fetchall()
上面的sql语句中“WHERE line=:line” :line相当于是一个占位符,随后在下面的execute方法中的第二个参数以字典的形式传入数据即可
注:字典中的变量名必须和上方的“:line”中的名字相同。
仅作个人记录,如有错误烦请纠正!