怎么把查询出的一条数据 的几个字段,放在一个字段上多行显示?

怎么把查询出的一条数据 的几个字段,放在一个字段上多行显示?:

🚀 思路:

① 首先用 concat 把多个字段拼装在一个字段中
② 然后用 mysql.help_topic 去切割该字段

🚀 过程:

①用 concat 把多个字段拼装在一个字段中(记作为①)

SELECT concat( supervisor_code, ',', construction_code, ',', build_code ) AS VALUE 
FROM project_section 
WHERE delete_flag=0 and section_code ='GC01-2'

查询结果①:
在这里插入图片描述

②用 mysql.help_topic 去切割该字段

SELECT
	substring_index( substring_index(, ',', b.help_topic_id + 1 ), ',',- 1 ) AS org_no 
	FROMJOIN mysql.help_topic b 
	ON b.help_topic_id < ( length() - length( REPLACE (, ',', '' ))+ 1 ) 

查询结果②:
在这里插入图片描述

🚀 总结:

完整sql:

SELECT
	substring_index( substring_index( a.VALUE, ',', b.help_topic_id + 1 ), ',',- 1 ) AS org_no 
	FROM
	( 
		SELECT concat( supervisor_code, ',', construction_code, ',', build_code ) AS VALUE 
		FROM project_section 
		WHERE delete_flag=0 and section_code ='GC01-2'  
	) AS a
	JOIN mysql.help_topic b 
	ON b.help_topic_id < ( length( a.VALUE ) - length( REPLACE ( a.VALUE, ',', '' ))+ 1 ) 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值