问题
How do I create this SQL using ZF2?
WITH q AS
(
SELECT m.*, CAST(ROW_NUMBER() OVER (ORDER BY m.PersonId) AS VARCHAR(MAX)) COLLATE Latin1_General_BIN AS bc
FROM mytable m
WHERE ParentID IS NULL
UNION ALL
SELECT m.*, q.bc + '.' + CAST(ROW_NUMBER() OVER (PARTITION BY m.ParentID ORDER BY m.PersonID) AS VARCHAR(MAX)) COLLATE Latin1_General_BIN
FROM mytable m
JOIN q
ON m.parentID = q.PersonID
)
SELECT *
FROM q
ORDER BY
bc
From: https://stackoverflow.com/a/1757302/351785
Starting in a model, I can do the last bit:
$this->tableGateway->select()->orderBy('bc');
It's the WITH
section I need help with.
来源:https://stackoverflow.com/questions/43742465/using-zf2-create-a-with-statement