Using ZF2, create a WITH statement?

喜欢而已 提交于 2019-12-25 10:21:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!