如何使用Rails3语法编写此MySql查询?

时间:2010-10-14 13:56:41

标签: ruby ruby-on-rails-3 ruby-1.9

SELECT  `subscriptions`.*, DATE_ADD(`subscriptions`.created_at, INTERVAL `packages`.validity DAY) as end_date
     FROM  `subscriptions`  INNER JOIN `packages` ON `packages`.`id` = `subscriptions`.`package_id`
    order by end_date;

1 个答案:

答案 0 :(得分:0)

假设您有一个模型Subscription,它是ActiveRecord :: Base的子类 然后它只是

Subsccription.select(“subscriptions。*,DATE_ADD(subscriptions。created_at,INTERVAL packages。validity DAY)as end_date).joins(:packages).order(:end_date )

我可能有一些语法错误,例如它可能是:package not:packages。但基本