我有一个复杂的 sql 查询,不知道如何转化为 Rails 方式的查询,sql 如下
SELECT
ID.LEVEL,
t.*
FROM
(
SELECT
@id AS _id, ( SELECT @id := parent_id FROM product_categories WHERE id = @id),
@l := @l + 1 AS LEVEL
FROM
product_categories, (SELECT @id := 100, @l := 0) as b
WHERE
@id > 0 ) as ID,
product_categories as t
WHERE
ID._id = t.id
ORDER BY `LEVEL`;
我尝试这样使用
ProductCategory.find_by_sql("xxx")
但是会报错。