您的位置:首页 > 数据库 > Oracle

oracle-function-wm_concat

2015-10-18 21:47 459 查看
转自:http://database.51cto.com/art/201010/231126.htm

表结构:

create table SHOPPING

(

  u_id  NUMBER,

  goods VARCHAR2(30),

  num   NUMBER(10,2)

)

原数据:

select * from shopping;

1    苹果    2.00

2    香梨    5.00

1    西瓜    4.00

3    葡萄    1.00

3    香蕉    1.00

1    橘子    3.00

期望结果一:

1    苹果,橘子,西瓜

2    香梨

3    葡萄,香蕉

查询语句:

select u_id, wmsys.wm_concat(goods) goods_list

from shopping

group by u_id;

期望结果二:

1    苹果(2斤),橘子(3斤),西瓜(4斤)

2    香梨(5斤)

3    葡萄(1斤),香蕉(1斤)

查询语句:

select u_id, wmsys.wm_concat(goods || '(' || num || '斤)' ) goods_sum  

from shopping  

group by u_id;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: