Can AR manage complex statements such as the following?
SELECT COUNT(P2.emp) AS indentation, P1.emp
FROM Personnel AS P1, Personnel AS P2
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
GROUP BY P1.emp
ORDER BY P1.lft;
From: http://www.ibase.ru/devinfo/DBMSTrees/sqltrees.html
My variation of the SQL is:
SELECT COUNT(R2.name) AS indentation, R1.name FROM Regions AS R1, Regions AS R2 WHERE R1.lft BETWEEN R2.lft AND R2.rgt GROUP BY R1.name ORDER BY R1.lft
I have located the following but have no idea how to link it all together.
.count(R2.name)
.where(R1.lft: R2.lft..R2.rgt)
.group("R1.name")
.order("R1.lft")
.where('R1.lft BETWEEN R2.lft AND R2.rgt') .group("R1.name") .order("R1.lft").select('COUNT(P2.emp) AS indentation, P1.emp')NOT TESTED. But shall work