首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在子查询中使用LISTAGG输出。甲骨文

问无法在子查询中使用LISTAGG输出。甲骨文
EN

Stack Overflow用户
提问于 2018-02-04 21:31:51
回答 1查看 480关注 0票数 0

我从下面的查询中获取逗号分隔值

SELECT LISTAGG('''' || student_name || '''',',') WITHIN GROUP (ORDER BY student_name) FROM students;

但是,当我放入子查询时,它不会给出任何结果。

select * from students where student_name in ('A', 'B'); --提供两行

select * from students where student_name in (SELECT LISTAGG('''' || student_name || '''',',') WITHIN GROUP (ORDER BY student_name) FROM students;) --没有行

EN

回答 1

Stack Overflow用户

发布于 2018-02-04 21:35:14

您不了解in是如何工作的。它不适用于字符串。它可以处理多个项目。

因此,编写逻辑的正确方法是:

代码语言:javascript
复制
select  *
from students
where student_name in (select student_name from students) -- no rows;

您的查询实际上是在执行以下操作:

代码语言:javascript
复制
where student_name in ('aaron,beth,calvin,debbie,...')

in列表只有一项,所以这相当于:

代码语言:javascript
复制
where student_name = 'aaron,beth,calvin,debbie,...'

并且没有学生姓名(如果您有多行)可以是所有学生的串联姓名。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48608592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档