按时间段分组_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > 按时间段分组

按时间段分组

 2011/12/5 7:34:42  夜鸣猪  http://hlee.iteye.com  我要评论(0)
  • 摘要:PostgreSQL:User.count(:order=>'DATE(created_at)DESC',:group=>["DATE(created_at)"])User.count(:order=>'DATE(created_at)DESC',:group=>["DATE(created_at)"]).each{|u|puts"#{u[0]}->#{u[1]}"}Foo.order("DATE(start_at)").group("DATE(start_at
  • 标签:

PostgreSQL
User.count(:order => 'DATE(created_at) DESC', :group => ["DATE(created_at)"])


User.count(:order => 'DATE(created_at) DESC', :group => ["DATE(created_at)"]).each {|u| puts "#{u[0]} -> #{u[1]}" }



Foo.order("DATE(start_at)").group("DATE(start_at)").count


Mysql在另一篇,heroku啊,让我学习postgresql

select floor(datediff(now(), created) / 3) * 3 as days_ago
      ,min(created)
      ,max(created)
      ,count(*)
  from t1
 group 
    by floor(datediff(now(), created) / 3);




https://github.com/Bantik/seer

# declare a struct to hold the results
UserCountByDate = Struct.new(:date, :count) 

def report
  @user_counts = User.count( :group => "DATE(created_at)", 
                   :conditions => ["created_at >= ? ", 7.days.ago], 
                   :order => "DATE(created_at) ASC"
                 ).collect do |date, count| 
                   UserCountByDate.new(date, count)
                 end

end



<div id="chart"></div>

<%= Seer::visualize(
      @user_counts, 
      :as => :column_chart,
      :in_element =>'chart', 
      :series => {
        :series_label => 'date',
        :data_method => 'count'
      },
      :chart_options => {
        :height => 300,
        :width => 100 * @user_counts.size,
        :is_3_d => true,
        :legend => 'none',
        :colors => "[{color:'#990000', darker:'#660000'}]",
        :title => "New users in last 7 days",
        :title_x => 'date',
        :title_y => 'count'
      }
    )
 -%>

  • 相关文章
发表评论
用户名: 匿名