skip to main
|
skip to sidebar
memo temp
2008年12月17日 星期三
sql,DATE,group by
想要計算某些column 每天的總數時, 可以用sql 的
DATE
#select 出這個月份每天的render 數
>> Render.count(:all, :conditions => {:created_at => Time.now.beginning_of_month..Time.now}, :group => 'DATE(created_at)')
SELECT count(*) AS count_all, DATE(created_at) AS date_created_at FROM `renders` WHERE (`renders`.`created_at` BETWEEN '2008-12-01 00:00:00' AND '2008-12-17 16:09:20') GROUP BY DATE(created_at)
=> [["2008-12-16", 1], ["2008-12-17", 24]]
結果出來是 OrderedHash 所以要用
hash["2008-12-16"] 去取值, 當然hash 的相關method 也可以用
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
state chart
eb
關於我自己
Lake
檢視我的完整簡介
pie chart
網誌存檔
►
2010
(1)
►
11月
(1)
►
2009
(26)
►
1月
(26)
▼
2008
(26)
▼
12月
(26)
[HTML] IE 表單 Enter 的 Bug
ruby memo
rails default mode
deploy
Gem dependencies
liquid,dynamic content
All About Layouts
rails 2.2 extra, delegate,gem
each_with_object,inject
header, redirect_to , render js, polymorphic_path
Rescue from dispatching, layout mailer
Shallow Routes, Resources With Specific Actions
etag,last_modified,Get
rails, thread-safe
alias_method_chain
rails2.2 extra, dynamic finder
join,include
sql,DATE,group by
Block in views, concat, capture, content_for,yield...
memoizable,rails2.2
overwrite attr_writer,=
rails I18n sample
rails execute sql
jquery parse xml
google ajax library api
using jquery in rails,jquery, rails,form,reset,esc...
沒有留言:
張貼留言