msyql 行轉列,字串根據相應字元拆分多行

2021-10-09 02:46:44 字數 1894 閱讀 9114

select

substring_index(substring_index( a.

chain

,'_'

,b.help_topic_id +1)

,'_',-

1)as id

from

-- 替換為自己的表, 上下欄位改一下就行

(select

'1_11_1223_1242'

aschain

) a

join mysql.help_topic b on b.help_topic_id <

(length(a.

chain

)- length(

replace

(a.chain

,'_',''

))+1

)

select

substring_index(substring_index( a.dev_id,

',',b.help_topic_id +1)

,',',-

1)as id,a.

*from

(select

t_sync_project.prj_name as

'專案名稱'

, t_sync_project.prj_local_addr as

'專案位址'

, t_sync_project.prj_status as

'專案狀態'

, t_sync_device_remove.remove_declare_date as

'申報時間'

, t_sync_device_remove.remove_describe as

'拆機備註'

, t_sync_device_remove.agree_remove_date as

'同意拆除時間'

, t_sync_device_remove.plan_remove_date as

'計畫拆除時間'

, t_sync_device_remove.actual_remove_date as

'實際拆除時間'

, t_sync_device_remove.

`status`as

'進度'

,case

when t_sync_device_remove.service_operator =

1then

'電信'

when t_sync_device_remove.service_operator =

2then

'移動'

when t_sync_device_remove.service_operator =

3then

'聯通'

else

''end

as'運營商'

, t_sync_project.prj_belong_addr as

'區域'

, t_sync_device_remove.dc_pk as

'工單號'

, t_sync_device_remove.dev_id as dev_id

from

t_sync_device_remove

left

join t_sync_project on t_sync_project.pro_id = t_sync_device_remove.pro_id) a

join mysql.help_topic b on b.help_topic_id <

(length(a.dev_id)

- length(

replace

(a.dev_id,

',','')

)+1)

hive 字串拼接 Hive行轉列詳解

孫悟空 白羊座 a 沙悟淨 射手座 a 宋鬆鬆 白羊座 b 豬八戒 白羊座 a 小鳳姐 射手座 a 轉換成以下格式 白羊座,a 孫悟空 豬八戒 白羊座,b 宋鬆鬆 射手座,a 沙悟淨 小鳳姐 知識點 concat string1,string2 string1和string2需要是列名 使用hive...

根據字元分割字串

create or replace procedure get split v string1 in varchar2,輸入的字串 v start in number,開始擷取的位置 v length in number,擷取的字元個數 v split in varchar2 分隔符號 as v s...

根據字串分組

今天要做乙個根據字串分組,然後集體執行乙個操作,想了一上午,動態建立陣列什麼的,最後還是用了list。list alllist new arraylist string m1 a123 x1 string m2 a124 x1 string m3 a125 x2 string m4 a126 x2 ...