【发布时间】:2017-09-14 20:45:51
【问题描述】:
假设我有
class KdpReport < ActiveRecord::Base
end
如何使用活动记录模型在 ruby 中翻译这条 sql 语句?
SELECT DISTINCT
`kdp_reports`.`date` AS `date`,
`kdp_reports`.`book_title` AS `book_title`,
`kdp_reports`.`marketplace` AS `marketplace`
FROM
`kdp_reports`
我使用红宝石“2.4.0” 和没有轨道的活动记录宝石
我只能想到这样的事情:
KdpReport.select(:date).distinct.select(:book_title).distinct.select(:marketplace).distinct
【问题讨论】:
-
您提出的解决方案完全符合您的要求。问题是什么?请停止在 StackOverflow 上发帖。
标签: sql ruby activerecord