我有一张表如下
|Cutomers|Orders|Items|
|Cutomer1|Order1|Item1|
|Cutomer1|Order1|Item2|
|Cutomer1|Order1|Item3|
|Cutomer1|Order2|Item1|
|Cutomer1|Order2|Item3|
|Cutomer1|Order2|Item4|
|Cutomer2|Order1|Item6|
| . | . | . |
| . | . | . |
| . | . | . |
我想拥有下表,看起来很简单,但我不知道如何处理它。
|Customers|Items|
|Customer1|Item1|
|Customer1|Item2|
|Customer1|Item3|
|Customer1|Item4|
|Customer2|Item6|
| . | . |
| . | . |
| . | . |
非常感谢任何建议!
答案 0 :(得分:3)
我认为这就足够了
select distinct Customers, Items
from YourTable
答案 1 :(得分:1)
从Oracle 11gR2开始,LISTAGG子句可以解决这个问题:
SELECT customers,
LISTAGG(items, ',') WITHIN GROUP (ORDER BY items)
FROM YOUR_TABLE
GROUP BY customers;
试试这个,它可能会起作用
你也可以wm_concat
SELECT customers, wm_concat(items) as item
FROM table
GROUP BY customers;
它可能也有效
我的sql,
select distinct customers, items from tablename