擅长:python、mysql、java
<p>希望这段代码能对你有所帮助。
只需在运动员课程中增加混合动力车属性。在</p>
<pre><code>from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.sql.expression import select, func
class Athlete(Base):
__tablename__ = 'athletes'
id = Column(Integer, primary_key=True)
@hybrid_property
def product_of_score(self):
return sum(r.score for r in self.scores)
@product_of_score.expression
def product_of_score(self):
return select([func.sum(Score.score)]).\
where(Score.athlete_id==self.id).\
label('product_of_score')
</code></pre>
<p>问题是:</p>
^{pr2}$