Rake file with Controller

Now am in a situation, that is I have one query for selecting the data from database, so when the rake file is running, this query need to execute, and do the operation…My problem is how to execute this query.? One thing i got in mind, call a method in a rake, in which method write the query for the operation,i don’t know the correct way…How to rectify this problem…?

i mean have any other solution ? or can i call a class or a controller from the rake…?

Thank you