如何在rails上将以下sql查询转换为ruby?
select health_workers.name,health_workers.surname,clinics.name as clinic,count(observations.id) as count,observations.observation_date
from health_workers
left join observations on health_workers.id = observations.health_worker_id, clinics
where health_workers.clinic_id = clinics.id
group by health_workers.name,health_workers.surname,clinics.name,observations.observation_date.
答案 0 :(得分:0)
你可以这样做
query = "select health_workers.name,health_workers.surname,clinics.name as clinic,count(observations.id) as count,observations.observation_date
from health_workers
left join observations on health_workers.id = observations.health_worker_id, clinics
where health_workers.clinic_id = clinics.id
group by health_workers.name,health_workers.surname,clinics.name,observations.observation_date."
results = ActiveRecord::Base.connection.execute(query)
这将为您提供结果