原创作者: hideto
阅读:2929次
评论:0条
更新时间:2011-05-26
ActiveRecord::Calculations模块提供了model级的方法来得到model数据的count,sum,average,maximum和minimum值
例如:
例如:
Person.count("age > 21") Person.average(:age) Person.minimum(:age) Person.maximum(:age) Person.average(:age, :conditions => ["name like ?", '%T%']) Donation.sum(:amount, :group => :created_at) Donation.sum(:amount, :group => 'YEAR(created_at)') Rating.average(:value, :group => :post).collect{|post, rating| [post.title, rating]} Rating.average(:value, :group => :post)[Post.find(2)] Person.find_by_name("Adam").ratings.average(:value)
评论 共 0 条 请登录后发表评论