涉及表:
rpt_1(
id,
relatioship1 ,
related_cust_id1 ,
relatioship2 ,
related_cust_id2 ,
relatioship3 ,
related_cust_id3 ,
relatioship4 ,
related_cust_id4 ,
relatioship5 ,
related_cust_id5 ,
relatioship6 ,
related_cust_id6 ,
relatioship7 ,
related_cust_id7 ,
relatioship8 ,
related_cust_id8 ,
relatioship9 ,
related_cust_id9 ,
relatioship10 ,
related_cust_id10,
relatioship11 ,
related_cust_id11,
relatioship12 ,
related_cust_id12,
relatioship13 ,
related_cust_id13,
relatioship14 ,
related_cust_id14,
relatioship15 ,
related_cust_id15
)
obj_abc(
id,
code,
name
)
需实现的结果:rpt_1表连(id)obj_abc表用code,name字段填充rpt_1的relatioship,related_cust_id字段,无值为null;id为rpt_1表主键,在表obj_abc中一个id下有N(N<=15)个code,name.
实现方法:
update rpt_1 rpt
set (rpt.relatioship1 ,
rpt.related_cust_id1 ,
rpt.relatioship2 ,
rpt.related_cust_id2 ,
rpt.relatioship3 ,
rpt.related_cust_id3 ,
rpt.relatioship4 ,
rpt.related_cust_id4 ,
rpt.relatioship5 ,
rpt.related_cust_id5 ,
rpt.relatioship6 ,
rpt.related_cust_id6 ,
rpt.relatioship7 ,
rpt.related_cust_id7 ,
rpt.relatioship8 ,
rpt.related_cust_id8 ,
rpt.relatioship9 ,
rpt.related_cust_id9 ,
rpt.relatioship10 ,
rpt.related_cust_id10,
rpt.relatioship11 ,
rpt.related_cust_id11,
rpt.relatioship12 ,
rpt.related_cust_id12,
rpt.relatioship13 ,
rpt.related_cust_id13,
rpt.relatioship14 ,
rpt.related_cust_id14,
rpt.relatioship15 ,
rpt.related_cust_id15) =
(select max(case when ron=1 then code end),
max(case when ron=1 then name end),
max(case when ron=2 then code end),
max(case when ron=2 then name end),
max(case when ron=3 then code end),
max(case when ron=3 then name end),
max(case when ron=4 then code end),
max(case when ron=4 then name end),
max(case when ron=5 then code end),
max(case when ron=5 then name end),
max(case when ron=6 then code end),
max(case when ron=6 then name end),
max(case when ron=7 then code end),
max(case when ron=7 then name end),
max(case when ron=8 then code end),
max(case when ron=8 then name end),
max(case when ron=9 then code end),
max(case when ron=9 then name end),
max(case when ron=10 then code end),
max(case when ron=10 then name end),
max(case when ron=11 then code end),
max(case when ron=11 then name end),
max(case when ron=12 then code end),
max(case when ron=12 then name end),
max(case when ron=13 then code end),
max(case when ron=13 then name end),
max(case when ron=14 then code end),
max(case when ron=14 then name end),
max(case when ron=15 then code end),
max(case when ron=15 then name end)
from (select id,code,name, row_number() over(partition by id order by code) ron from obj_abc) tmp
where tmp.id = rpt.id
);
分享到:
相关推荐
行列互换工具毫秒级_V2.2.2行列转换
orcale数据库 行列互换orcale数据库 行列互换orcale数据库 行列互换
实现数组的行列互换 形参使用二维数组。函数调用使用引用传递,比较基础。
两种方法进行sql行列互换 假设有张学生成绩表(tb)如下: Name Subject Result 张三 语文 74 张三 数学 83 张三 物理 93 李四 语文 74 李四 数学 84 李四 物理 94 */ -----------------------------...
行列互换工具毫秒级
C语言程序设计-编写程序,实现矩阵(3行3列)的转置(即行列互换)
oracle_lhr_行列互换总结oracle_lhr_行列互换总结oracle_lhr_行列互换总结
巧借Excel快速把Word表格行列互换
sql行列互换常用代码,包括SQL Server2000的版本和SQL Server2005版本。
关于oracle的查询结果的行列互换.docx sql经典
写一个函数名为convert,实现将给定的3× 3的整型数组转置(行列互换)。 要求:(1)由键盘按矩阵的形式输入3× 3的整型数组。 (2)函数的原型为:void convert(int b[3][3]) (3)在源程序中书写必要的注释。
主要介绍了C#实现DataGridView控件行列互换的方法,涉及C#中DataGridView控件元素遍历与添加操作的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
codenames type flag zhao a y zhao b n zhao c y li a n li b y li c y 查询出来为
SQL 实现行列互换。例题,可以仿照写自己的SQL语句!注意语法
使用SQL语句,实现数据库查询结果的行列互换。
本文档提供了一个sql server中行列互换的实例sql语句。
1_行列互换.cpp
互换二维数组的行与列,使用记事本打开,数组操作
用Excel把网页上复制来的文本行列互换.docx