将多个行组合在一起的Sql查询。

时间:2022-08-24 21:34:01

I have a table as follows

我有一张如下表。

|Cutomers|Orders|Items| |Cutomer1|Order1|Item1| |Cutomer1|Order1|Item2| |Cutomer1|Order1|Item3| |Cutomer1|Order2|Item1| |Cutomer1|Order2|Item3| |Cutomer1|Order2|Item4| |Cutomer2|Order1|Item6| | . | . | . | | . | . | . | | . | . | . |

在此基础上,我们将对|项下的|项下的|、|1、|1、|1、|1、bb16、bp18、bp18、bp21、|1、|1、bp21、|6、bp25、|6、bp28、|6、|7、bp28、|7、bp28、|6、|7、bpb27、|7、bpb2|7、|7、|7、bp2|7、|6、|7、|7、bpb27、|7、|7、|7、|7、|7、|6、|7、bpb2|7、|7、|7、|7、|3、|7、bb2||0、|7、bb2||0、|6、|3、|3、|7、bpb23、|6、|6、|3、|6、|7、bb2||0、|9、|9、|。|。| |。|。|。| |。|。|。|

I want to have the following table, seems like easy but i have no clue how to deal with it.

我想要下表,看起来很简单,但是我不知道怎么处理。

|Customers|Items| |Customer1|Item1| |Customer1|Item2| |Customer1|Item3| |Customer1|Item4| |Customer2|Item6| | . | . | | . | . | | . | . |

(1)| | | | | | | | | | | | | |1 |1 |1 |1 |4 |4 |4 |4 |6 |6 |6 |6 |6 |6 |6 |6 |6 |6 |7 |7 |7 |7 |7 |6 |6 |6 |6 |6 |7 |6 |6 |6 |6 |7 |6 |6 |6 |6 |7 |6|。| |。|。| |。|。|

Any suggestions are very much appreciated!

非常感谢您的建议!

2 个解决方案

#1


3  

I think this would suffice

我想这就够了。

select  distinct Customers, Items
from    YourTable

#2


1  

From Oracle 11gR2, the LISTAGG clause should do the trick:

在Oracle 11gR2中,LISTAGG子句应该执行以下操作:

SELECT customers,
       LISTAGG(items, ',') WITHIN GROUP (ORDER BY items)
FROM YOUR_TABLE
GROUP BY customers;

try this, it might work

试试这个,它可能有用。

you can also wm_concat

你也可以wm_concat

SELECT customers, wm_concat(items) as item
FROM   table
GROUP BY customers;

it might also work

它还可能工作

for my sql,

为我的sql,

select  distinct customers, items from tablename

#1


3  

I think this would suffice

我想这就够了。

select  distinct Customers, Items
from    YourTable

#2


1  

From Oracle 11gR2, the LISTAGG clause should do the trick:

在Oracle 11gR2中,LISTAGG子句应该执行以下操作:

SELECT customers,
       LISTAGG(items, ',') WITHIN GROUP (ORDER BY items)
FROM YOUR_TABLE
GROUP BY customers;

try this, it might work

试试这个,它可能有用。

you can also wm_concat

你也可以wm_concat

SELECT customers, wm_concat(items) as item
FROM   table
GROUP BY customers;

it might also work

它还可能工作

for my sql,

为我的sql,

select  distinct customers, items from tablename