我想識別和計算具有特定數量的消息和post.location不是零的帖子。紅寶石複雜計數
我有大約100k行,這是統計使用,所以我需要快速查詢(我可能必須通過這種方式索引post.location)。
我該如何做到最簡單,最快捷的方式?
這裏是我的架構:
create_table "posts", :force => true do |t|
t.string "ref"
t.string "title"
t.string "author"
t.datetime "created_at"
t.datetime "updated_at"
t.string "location"
t.float "lat"
t.float "long"
end
create_table "messages", :force => true do |t|
t.integer "post_id"
t.integer "status_id"
t.integer "user_id"
t.string "content"
t.datetime "created_at"
t.datetime "updated_at"
t.float "lat"
t.float "long"
end
add_index "messages", ["post_id"], :name => "index_messages_on_post_id"
add_index "messages", ["created_at"], :name => "index_messages_on_created_at"
這看起來不錯,我如何驗證post.location不是零? – PEF 2012-07-30 09:24:32
我剛更新了答案.. – Tigraine 2012-07-30 11:38:03