結果モデルに、:measurement_id、:test_id、:player_id、:no、:resを含むいくつかのテストの結果があります。ここで、noはテストの数(たとえば、1-first、2-secondなど)であり、:resはresaultです。そのテストの。
今、私はこのようなことをするメソッドを書きたいと思います:
Result.where(:measurement_id = xx、:test_id = zz、:player_id = yy).finalresault
そしてfinalresaultは、テーブルにあるすべての:resを探して計算し、平均値を言ってそれを返します。
そのような方法で行うことは可能ですか?
ありがとうございました
これがモデルの様子で、私は何かを書き込もうとしていました...:
class Result < ActiveRecord::Base
attr_accessible :measurement_id, :test_id, :player_id, :no, :res
belongs_to :test
def finalresault
end
end