oracle 行列转换

来源:互联网 发布:兰蔻臻白精华乳 知乎 编辑:程序博客网 时间:2024/06/05 09:53

突然需要用到sql行列转换,就上网查了查,由于用的是oracle,发现一个函数比较好用,简单省事:

select B from ( select A,wm_concat(B) as B from TABLE group by A) where A='6' ;
A:分组条件
B:需要转化的列

创建表:

create table testlcl(       id   VARCHAR2(48) not null,       book_name VARCHAR2(48),       genre_id   VARCHAR2(48) not null,       genre VARCHAR2(48)   )

插入信息:


目的:查询每种类别下的所有书籍信息:

select genre_id,wm_concat('id:'||id||'-'||'书名:'||book_name||'-类别:'||genre) as info from testlcl group by genre_id;
效果:


补:例子不是很好,当时我解决问题的场景是:表中是多对多的数据,需要获取每种物品的所有所属类(即:企业归属商业类,企业归属行业类),返回字符串。



0 0
原创粉丝点击