我盯着我的代码看了一个多小时,但我仍然无法弄清楚我的查询出了什么问题。我收到错误消息:ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near ")" LINE 38: WHERE (abs(ax2 - ?) / ? < ?)
query = %Q{
SELECT
avg(ax2),
avg(ay2),
avg(az2)
FROM (
SELECT
avg(t1) as t2,
avg(n1) as n2,
avg(ax1) as ax2,
avg(ay1) as ay2,
avg(az1) as az2
FROM (
SELECT
avg(t) as t1,
avg(n) as n1,
avg(ax) as ax1,
avg(ay) as ay1,
avg(az) as az1
FROM obds
WHERE uid = #{uid} AND (ev = 6011 or ev = 6012)
GROUP BY
round(t,3),
round(n,3)
)
AS derivedTable1
GROUP BY round(t1 + 0.0005,3), round(n1 + 0.0005,3)
)
AS derivedTable2
WHERE (abs(ax2 - ?) / ? < ?) #<<<<< Line with error
}
binds = [ uid, x_average, x_average, THRESHOLD_FOR_RESTING ]
result = Ozd.find_by_sql query, binds