I need to convert the following query to Arel and I don't see any documentation convert the
(SELECT @row_index:=-1) AS r
into Arel query. For context the full query is like this.
SELECT AVG(subq.#{column_name}) as median_value, (SELECT @row_index:=-1) AS r, '#{type}' as median_type
FROM (
SELECT @row_index:=@row_index + 1 AS row_index, #{column_name}
FROM location_markets
WHERE #{where} AND location_type = '#{location_type}' AND #{column_name} is NOT NULL
ORDER BY #{column_name}
) AS subq
WHERE subq.row_index IN (FLOOR(@row_index / 2) , CEIL(@row_index / 2))
Not sure how to write the select statement in Arel for this query.
You can write pretty much anything in
Arelbut in this case it might not make a lot of sense.UPDATE Full Translation:
Result