DB2子查询中的CTE

编程入门 行业动态 更新时间:2024-10-26 17:28:07
本文介绍了DB2子查询中的CTE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图在DB2 luw 11.1的from子句中使用递归CTE.此CTE本身是有效的:

I'm trying to use a recursive CTE in the from clause in DB2 luw 11.1. This CTE works by itself:

with i (i) as ( values (1) union all select i + 1 from i where i < 3 ) select * from i; I ------------- 1 2 3

但是当我在 from 子句中尝试时:

But when I try it in the from clause:

select * from ( with i (i) as ( values (1) union all select i + 1 from i where i < 3 ) select * from i ) i; ERRO próximo da linha 1: SQL0104N An unexpected token "as" was found following "* from ( with i (i)". Expected tokens may include: "JOIN".

在Postgresql中也可以使用类似的构造.我想念什么?

A similar construct works in Postgresql. What am I missing?

推荐答案

在DB2查询中必须首先使用"with"语句,请尝试

Hi "with" statement must be first in db2 query ,try this

with i (i) as ( values (1) union all select i + 1 from i where i < 3 ) select * from ( select * from i ) i;

更多推荐

DB2子查询中的CTE

本文发布于:2023-10-13 14:24:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1488204.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CTE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!