字符串拼接列转行

当前页面中仅仅显示物品的价格信息

在这里插入图片描述
代码如下所示:
发现没有数据
SELECT
(SELECT wm_concat(dj) FROM CG_CGLXMXB LXMX WHERE XMBH = LXMXB.XMBH AND LXMX.XFKS = ‘6423B8ACD0368AFCE050A8C0D90A1950’) QTJG
FROM CG_CGLXB LX
LEFT JOIN CG_CGHTB HT ON HT.XMBH = LX.XMBH
LEFT JOIN CG_XMMCB XMMC ON XMMC.GID = LX.XMMC
LEFT JOIN OA_SYS_DWB DW ON DW.DWBH = LX.SQDW
LEFT JOIN OA_SYS_DWB SJDW ON SJDW.DWBH = DW.SJDW
LEFT JOIN (SELECT XMBH, SUM(SHL) ZTS, SUM(ZJ) ZJE, WM_CONCAT(DISTINCT KS.XFKS) DHXL
FROM CG_CGLXMXB MX
LEFT JOIN HQ_KS KS ON KS.GID = MX.XFKS GROUP BY XMBH) LXMXB ON LXMXB.XMBH = LX.XMBH
LEFT JOIN CG_CGYSB YS ON YS.XMBH = LX.XMBH
LEFT JOIN CG_GYSB GYS
ON GYS.GYSBH = YS.QY WHERE LX.ZTBZ = ‘11’
AND DW.SCHOOL = ‘SCHOOL’
现在需要做的功能是需要将将字符串拼接并且列转行
代码如下
在这里插入图片描述
SELECT
(SELECT to_char(wm_concat(wpmc||’(’||dj||’)’) ) FROM CG_CGLXMXB LXMX WHERE XMBH = LXMXB.XMBH AND LXMX.XFKS = ‘6423B8ACD0368AFCE050A8C0D90A1950’) QTJG
FROM CG_CGLXB LX
LEFT JOIN CG_CGHTB HT ON HT.XMBH = LX.XMBH
LEFT JOIN CG_XMMCB XMMC ON XMMC.GID = LX.XMMC
LEFT JOIN OA_SYS_DWB DW ON DW.DWBH = LX.SQDW
LEFT JOIN OA_SYS_DWB SJDW ON SJDW.DWBH = DW.SJDW
LEFT JOIN (SELECT XMBH, SUM(SHL) ZTS, SUM(ZJ) ZJE, WM_CONCAT(DISTINCT KS.XFKS) DHXL
FROM CG_CGLXMXB MX
LEFT JOIN HQ_KS KS ON KS.GID = MX.XFKS GROUP BY XMBH) LXMXB ON LXMXB.XMBH = LX.XMBH
LEFT JOIN CG_CGYSB YS ON YS.XMBH = LX.XMBH
LEFT JOIN CG_GYSB GYS
ON GYS.GYSBH = YS.QY WHERE LX.ZTBZ = ‘11’
AND DW.SCHOOL = ‘SCHOOL’

在此基础上添加了 to_char(wm_concat(to_char(wpmc)||’(’||dj||’)’) )
有了相对应的数据
在这里插入图片描述
代码如下:
SELECT
(SELECT to_char(wm_concat(to_char(wpmc)||’(’||dj||’)’) ) FROM CG_CGLXMXB LXMX WHERE XMBH = LXMXB.XMBH AND LXMX.XFKS = ‘6423B8ACD0368AFCE050A8C0D90A1950’) QTJG
FROM CG_CGLXB LX
LEFT JOIN CG_CGHTB HT ON HT.XMBH = LX.XMBH
LEFT JOIN CG_XMMCB XMMC ON XMMC.GID = LX.XMMC
LEFT JOIN OA_SYS_DWB DW ON DW.DWBH = LX.SQDW
LEFT JOIN OA_SYS_DWB SJDW ON SJDW.DWBH = DW.SJDW
LEFT JOIN (SELECT XMBH, SUM(SHL) ZTS, SUM(ZJ) ZJE, WM_CONCAT(DISTINCT KS.XFKS) DHXL
FROM CG_CGLXMXB MX
LEFT JOIN HQ_KS KS ON KS.GID = MX.XFKS GROUP BY XMBH) LXMXB ON LXMXB.XMBH = LX.XMBH
LEFT JOIN CG_CGYSB YS ON YS.XMBH = LX.XMBH
LEFT JOIN CG_GYSB GYS
ON GYS.GYSBH = YS.QY WHERE LX.ZTBZ = ‘11’
AND DW.SCHOOL = ‘SCHOOL’

最后一步是替换掉所有的逗号

replace(to_char(wm_concat(to_char(wpmc) || ‘(’ || dj || ‘元)’)),’,’,’;’)

学习的转载连接
https://www.cnblogs.com/qianyuliang/p/6649983.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值