1

有没有什么简单的方法可以在 Ingres 9.2 中模拟 GROUP_CONCAT 功能?

我有一张桌子,上面有:

OrderID   LineNumber    LineText
1         1             This is an example note which is trunc
1         2             ated at a certain point.
2         1             Another note which is just one line.

等等。有些笔记是 1 行,有些是 50+ 行。

我想要一个查询返回:

OrderID  FullText
1        This is an example note which truncated at a certain point.
2        Another note which is just one line.

在 MySQL 或 SQLite 中,我会使用 GROUP_CONCAT。在 MS SQL 中更难,但我会使用 FOR XML 功能来实现解决方案。我不确定如何在 Ingres 中做到这一点。我开始编写一个存储过程,它可以返回单个订单 ID 的串联注释,但我看不到将其集成到我的查询中的简单方法。

有任何想法吗?

4

1 回答 1

2

这可能有效:

select OrderId,
       (max(case when LineNumber = 1 then LineText else '' end) +
        max(case when LineNumber = 2 then LineText else '' end) +
        max(case when LineNumber = 3 then LineText else '' end)
       ) as LineText
from t
group by Orderid;

你有它非常方便LineNumber

于 2013-05-28T16:37:11.723 回答