Informix - 将值列表聚合为逗号分隔的字符串

发布于 2024-09-24 19:08:45 字数 149 浏览 3 评论 0原文

Informix 中有没有办法将值列表转换为逗号分隔的字符串?例如,我有以下查询作为子选择:

SELECT [State] From States

我想将该选择中的所有值转换为逗号分隔的列表。

我可以在 informix 中这样做吗?

Is there a way to convert a list of values into a comma-delimited string in Informix? For example, I have the following query as a subselect:

SELECT [State] From States

I would like to convert all the values from that select into a comma-separated list.

Can I do that in informix?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独享拥抱 2024-10-01 19:08:45

我认为您需要的答案在这些问题中给出: SO 715350SO 489081。它展示了如何创建和使用 GROUP_CONCAT() 聚合来完全满足您的需求。否则该功能不可用 - 也就是说,您必须将其添加到 Informix,但它可以(相当)轻松地添加。

I think the answer you need is given in these questions: SO 715350, SO 489081. It shows how to create and use a GROUP_CONCAT() aggregate that will do exactly what you want. The functionality is otherwise not available - that is, you have to add it to Informix, but it can (fairly) easily be added.

夏末 2024-10-01 19:08:45

您始终可以使用递归 SQL

with 
  states (rn, state) as (
    select row_number() over (), s 
    from table (multiset {'a', 'b', 'c'}) as t (s)
  ),
  r (rn, s) as (
    select s.rn, cast(s.state as varchar(100))
    from states as s
    where s.rn = 1
    union all
    select s.rn, cast(r.s || ', ' || s.state as varchar(100))
    from states as s
    join r on s.rn = r.rn + 1
  )
select first 1 s 
from r
order by rn desc;

|s      |
|-------|
|a, b, c|

You can always use recursive SQL:

with 
  states (rn, state) as (
    select row_number() over (), s 
    from table (multiset {'a', 'b', 'c'}) as t (s)
  ),
  r (rn, s) as (
    select s.rn, cast(s.state as varchar(100))
    from states as s
    where s.rn = 1
    union all
    select s.rn, cast(r.s || ', ' || s.state as varchar(100))
    from states as s
    join r on s.rn = r.rn + 1
  )
select first 1 s 
from r
order by rn desc;

Producing:

|s      |
|-------|
|a, b, c|
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文