0

I have the following sql query and I want to map it to a rails count query:

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;

How do I do this?

1 Answer 1

4

In 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')

In rails 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')
Sign up to request clarification or add additional context in comments.

1 Comment

.select is not available in rails 2, i'm using rails 2.3.5 any suggestions ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.