SQL中怎么把多查询结果合并成一条数据

来源:百度知道 编辑:UC知道 时间:2024/06/30 17:47:44
如我查询语句是:
select * from k_t where k_n1=1 and k_n2=1 and k_n3=1 and k_n4=1
得到 结果是:
1,1,1,1,5
1,1,1,1,4
1,1,1,1,3现在我要把结果合并成
查询到到结果成[1,1,1,1,543]这样..有什么办法?

for c in(select * from k_t) loop

insert into k_t_tmp select 1,1,1,1,null from dual;

update k_t_tmp set k_n5=k_n5||c.k_n5;
commit;

end loop;

oralce 10g 函数 wm_concat

select k_n1,k_n2,k_n3,k_n4,wm_concat(k_n5) from k_t where k_n1=1 and k_n2=1 and k_n3=1 and k_n4=1

运行结果如下:
1 1 1 1 5,4,3

行列转换咯

或者CASE语句

这个查询叫行变列,是比较复杂的,我曾经做过一个,查询中要设置变量,具体怎么设置可以上CSDN搜。