使用ZF2,创建一个WITH语句?

时间:2017-05-02 16:03:56

标签: sql-server zend-framework2 with-statement

如何使用ZF2创建此SQL?

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

来自:https://stackoverflow.com/a/1757302/351785

从模型开始,我可以做最后一点:

$this->tableGateway->select()->orderBy('bc');

我需要帮助的WITH部分。

0 个答案:

没有答案