我希望有人可以帮助我。我正在查询我的数据库以找到具有最高数量“F1”的对象。但后来我想在它发生时返回日期。无法弄清楚如何构建第二个查询... 我的代码:
Object1 = Class(end_time = "2016-12-01T08:00:00+0000", F1 = 10)
Object2 = Class(end_time = "2016-12-02T08:00:00+0000", F1 = 20)
session.add_all([Object1, Object2])
session.commit()
#return the instance with the highest F1
F1_query = session.query(Class.F1).order_by(Class.F1.desc()).first()
peak_date = ????
print("The highest number of F1 was " + str(F1_query[0]) + " on..." + str(peak_date))
答案 0 :(得分:0)
f1, peak_date = session.query(Class.F1, Class.end_time).order_by(Class.F1.desc()).first()
print("The highest number of F1 was " + str(f1) + " on..." + str(peak_date))