2008年7月17日 星期四

group


Record.find(:all, :select => "user_id, sum(todo_time) as sum", :group => 'user_id').map(&:sum)
SELECT user_id, sum(todo_time) as sum FROM `records` GROUP BY user_id

Record.find(:all, :select => "user_id, sum(todo_time)", :group => 'user_id').map(&:'sum(todo_time)')
SELECT user_id, sum(todo_time) FROM `records` GROUP BY user_id

Record.find(:all, :select => "user_id, count(*) as count", :group => 'user_id').map {|u| [u.user_id, u.count]}
SELECT user_id, count(*) as count FROM `records` GROUP BY user_id

沒有留言: