SQL - WHERE 子句中的 With 语句
您好,
WITH 状态可以存在于 WHERE 子句中吗?
例如:
SELECT tbl1.name , tbl1.ID
FROM DBTABLE0001 AS tbl1
WHERE (
exists(
WITH H (super, ID, depth) AS
(
SELECT ROOT.parent, ROOT.ID , 0
FROM DBTABLE0001 ROOT
WHERE ROOT.ID = tbl1.ID
UNION ALL
SELECT PARENT.parent, PARENT.ID , CHILD.depth + 1
FROM H CHILD, DBTABLE0001 PARENT
WHERE PARENT.ID = CHILD.super
)
SELECT ID
FROM H
WEHER H.ID = "abcd"
ORDER BY depth
)
)
谢谢, 莫。
HI,
Does a WITH state can live in a WHERE clause?
for instance:
SELECT tbl1.name , tbl1.ID
FROM DBTABLE0001 AS tbl1
WHERE (
exists(
WITH H (super, ID, depth) AS
(
SELECT ROOT.parent, ROOT.ID , 0
FROM DBTABLE0001 ROOT
WHERE ROOT.ID = tbl1.ID
UNION ALL
SELECT PARENT.parent, PARENT.ID , CHILD.depth + 1
FROM H CHILD, DBTABLE0001 PARENT
WHERE PARENT.ID = CHILD.super
)
SELECT ID
FROM H
WEHER H.ID = "abcd"
ORDER BY depth
)
)
Thanks,
Mo.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将 with 语句放在查询的开头。那么你可以在任何地方使用它:
You should place your with statements at the begining of your query. then you can use it every where :