我在 rails 2 工作,我想执行 Query
PunchingInformation.all(
:select => "users.id, login, firstname, lastname,
sec_to_time(avg(time_to_sec(punching_informations.punch_in_time))) as 'avg_pit',
sec_to_time(avg(time_to_sec(punching_informations.punch_out_time))) as 'avg_pot'",
:joins => :user,
:group => "users.id",
:conditions => {
"punching_informations.date between '#{start_date}' and '#{end_date}'",
["punching_informations.user_id IN (?)", employees.map { |v| v.to_i } ]
}
)
但它总是返回错误,如
Mysql::Error: Unknown column 'punching_informations.date between '2012-09-01' and '2012-09-25'' in 'where clause': SELECT users.id,login, firstname,lastname, sec_to_time(avg(time_to_sec (punching_informations.punch_in_time))) as 'avg_pit', sec_to_time(avg(time_to_sec(punching_informations.punch_out_time))) as 'avg_pot' FROM
punching_informations
INNER JOINusers
ONusers
.id =punching_informations
.user_id AND (users
.type
= 'User' ORusers
.type
= 'AnonymousUser' ) WHERE (punching_informations
.date between '2012-09-01' and '2012-09-25'
IN ('punching_informations.user_id IN (?)','--- \n- 28\n- 90\n')) GROUP BY users.id
需要你的帮助。