我开发了我的网站,它在我的本地机器上就像一个魅力。该查询由该线程中的 Stackoverflow 成员提供。
本地数据与 Heroku 上的数据相同。
select *
from (
select *
, row_number() over (partition by odds_type order by odds_index desc) as rn2
from (
select *
, row_number() over (partition by event_id, bookmaker_id, odds_type
order by created_at desc) as rn1
from Odds
where event_id = #{e.id}
) sub1
where rn1 = 1
) sub2
where rn2 = 1
控制台中的错误
Odds Load (88.4ms) select * from ( select *, row_number() over (partition by odds_type order by odds_index desc) as rn2 from (select *, row_number() over (partition by event_id, bookmaker_id, odds_type order by created_at desc) as rn1 from Odds where event_id = 21 ) sub1 where rn1 = 1 ) sub2where rn2 = 1
ActiveRecord::StatementInvalid: PG::Error: ERROR: syntax error at or near "over"
LINE 1: select * from ( select *, row_number() over (partition by od...
^