按时间段分组
按时间段分组PostgreSQL:
Ruby代码1.User.count(:order => 'DATE(created_at) DESC', :group => ["DATE(created_at)"])
User.count(:order => 'DATE(created_at) DESC', :group => ["DATE(created_at)"])Ruby代码1.User.count(:order => 'DATE(created_at) DESC', :group => ["DATE(created_at)"]).each {|u| puts "#{u} -> #{u}" }
User.count(:order => 'DATE(created_at) DESC', :group => ["DATE(created_at)"]).each {|u| puts "#{u} -> #{u}" }Ruby代码1.Foo.order("DATE(start_at)").group("DATE(start_at)").count
Foo.order("DATE(start_at)").group("DATE(start_at)").countMysql在另一篇,heroku啊,让我学习postgresql
Ruby代码1.select floor(datediff(now(), created) / 3) * 3 as days_ago
2. ,min(created)
3. ,max(created)
4. ,count(*)
5.from t1
6. group
7. by floor(datediff(now(), created) / 3);
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
Ruby代码1.# declare a struct to hold the results
2.UserCountByDate = Struct.new(:date, :count)
3.
4.def report
5.@user_counts = User.count( :group => "DATE(created_at)",
6. :conditions => ["created_at >= ? ", 7.days.ago],
7. :order => "DATE(created_at) ASC"
8. ).collect do |date, count|
9. UserCountByDate.new(date, count)
10. end
11.
12.end
# 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)
endend
Html代码1.<div id="chart"></div>
2.
3.<%= Seer::visualize(
4. @user_counts,
5. :as => :column_chart,
6. :in_element =>'chart',
7. :series => {
8. :series_label => 'date',
9. :data_method => 'count'
10. },
11. :chart_options => {
12. :height => 300,
13. :width => 100 * @user_counts.size,
14. :is_3_d => true,
15. :legend => 'none',
16. :colors => "[{color:'#990000', darker:'#660000'}]",
17. :title => "New users in last 7 days",
18. :title_x => 'date',
19. :title_y => 'count'
20. }
21. )
22. -%> 谢谢分享希望于楼主多多交流 PostgreSQL其实挺好的,为啥PostgreSQL用户这么少呢?
页:
[1]