0
SELECT A.FirstName, A.LastName, B.PatientId, B.RoomNumber, B.AdmissionDate, B.DischargeDate, B.MeasureCategory 
FROM DimPatient A, DimPatientStay B 
WHERE A.Id = B.PatientId AND A.FirstName = 'Anuj' AND B.MeasureCategory = 'ED'

嗨,对此进行了一些更新,我解决了这个问题

MODELNAME.find_by_sql("your sql query")
4

3 回答 3

1

你可以试试这个从 Rails 中的 sql 查询中找到结果

query_params = Hash.new
    sql_query = "SELECT A.FirstName, A.LastName, B.PatientId, B.RoomNumber,    B.AdmissionDate, B.DischargeDate, B.MeasureCategory 
FROM DimPatient A, DimPatientStay B 
WHERE A.Id = B.PatientId AND A.FirstName = :first_name AND B.MeasureCategory = :measure_category"

query_params[:first_name] = first_name
query_params[:measure_category] = measure_category


@query_results = ActiveRecord::Base.connection.select_all(
  ActiveRecord::Base.send("sanitize_sql_array",[sql_query, query_params] )
)
于 2013-07-25T08:03:07.637 回答
0

我想你可以试试:

ActiveRecord::Base.connection().execute(#your_sql_here)
于 2013-07-25T07:34:06.250 回答
0

假设 A 是一个类而 B 是另一个类,您应该使用包括如下:

A.includes(:b).where(...) # add you condition in where

我建议在这里查看 ActiveRecord 的优秀视频教程

于 2013-07-25T07:34:50.190 回答