2011-12-15 91 views
0

我有以下SQL查詢,我想把它映射到一個軌道數查詢:轉換SQL查詢到Rails的Active Record查詢接口

SELECT count(*), DATE(CONVERT_TZ(created_at, '+00:00', '-05:00')) as converted_date 
FROM video_logs 
where user_id = 19 and question_id = 96 and dashboard = 'player_question' 
GROUP BY converted_date; 

我該怎麼辦呢?

回答

4

在Rails 3:

VideoLog.select("count(*), DATE(CONVERT_TZ(created_at, '+00:00', '-05:00')) as converted_date").\ 
    where(:user_id => 19, :question_id => 96, :dashboard => 'player_question').\ 
    group('converted_date') 

在軌道2:

VideoLog.all(:select => "count(*), DATE(CONVERT_TZ(created_at, '+00:00', '-05:00')) as converted_date", 
    :conditions => {:user_id => 19, :question_id => 96, :dashboard => 'player_question'}, 
    :group => 'converted_date') 
+0

。選擇不固定導軌2可用的,我使用的鐵軌2.3.5有什麼建議? – 2011-12-15 11:34:45

相關問題