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;
答案 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。但基本