激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|數據庫技術|

服務器之家 - 數據庫 - Mysql - MySQL將一個字段中以逗號分隔的取出來形成新的字段實現

MySQL將一個字段中以逗號分隔的取出來形成新的字段實現

2021-02-26 17:38舊夏潛入夢 Mysql

這篇文章主要介紹了MySQL將一個字段中以逗號分隔的取出來形成新的字段實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

1例如:要把如圖1的字段拆分圖2

MySQL將一個字段中以逗號分隔的取出來形成新的字段實現

MySQL將一個字段中以逗號分隔的取出來形成新的字段實現

?
1
2
3
4
5
6
7
8
9
select account_id,
    substring_index(substring_index(a.related_shop_ids,','
    ,b.help_topic_id+1),',',-1) shopid
  from
    sales_hang_account a
  join
    mysql.help_topic b
    on b.help_topic_id < (length(a.related_shop_ids) -   length(replace(a.related_shop_ids,',',''))+1)
  order by a.account_id

2:然后和shops表進行連接查詢取出我們需要的字段,我這里需要取出name

?
1
2
3
4
5
6
7
8
9
10
11
12
select s.`name` as shopname,a.account_id from shops s
inner join (
 
select account_id,
    substring_index(substring_index(a.related_shop_ids,','
    ,b.help_topic_id+1),',',-1) shopid
  from
    sales_hang_account a
  join
    mysql.help_topic b
    on b.help_topic_id < (length(a.related_shop_ids) -   length(replace(a.related_shop_ids,',',''))+1)
  order by a.account_id)a on s.shop_id=a.shopid

MySQL將一個字段中以逗號分隔的取出來形成新的字段實現

3:將 account_id相同合并成一行,以逗號隔開

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//這兩個是網上的例子
select id,group_concat(name) as name from table group by id;
 
select id,group_concat(name separator ';') as name from a group by id;
//借助上面兩個參考
select account_id,group_concat(shopname separator',')as shopname from (select s.`name` as shopname,a.account_id from shops s
inner join (
 
select account_id,
    substring_index(substring_index(a.related_shop_ids,','
    ,b.help_topic_id+1),',',-1) shopid
  from
    sales_hang_account a
  join
    mysql.help_topic b
    on b.help_topic_id < (length(a.related_shop_ids) -   length(replace(a.related_shop_ids,',',''))+1)
  order by a.account_id)a on s.shop_id=a.shopid) a group by account_id

效果如下

MySQL將一個字段中以逗號分隔的取出來形成新的字段實現

第二種方法

?
1
2
select g.account_id,g.related_shop_ids,group_concat(s.name)as shopname from sales_hang_account g left join shops s on find_in_set(s.shop_id , g.related_shop_ids)
group by g.account_id

MySQL將一個字段中以逗號分隔的取出來形成新的字段實現

sqlserver

?
1
2
3
[product] -- 該字段存儲格式為 7,8,9,11,10,12 ,數據類型為nvarchar
select id,productname=stuff((select ',' + product_chinaname from base_supplier_product where charindex(','+ltrim(productid)+',',','+ product + ',') > 0 for xml path('') ), 1, 1, '')
 from base_pre_sale_project

結果

MySQL將一個字段中以逗號分隔的取出來形成新的字段實現

到此這篇關于mysql將一個字段中以逗號分隔的取出來形成新的字段實現的文章就介紹到這了,更多相關mysql字段逗號分隔內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://www.cnblogs.com/weixin18/p/9827222.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美淫视频 | 亚洲精品久久久久www | 成人国产精品一区二区毛片在线 | 极品大长腿啪啪高潮露脸 | 久久精品视频免费观看 | 久久区二区 | 欧美性受ⅹ╳╳╳黑人a性爽 | 毛片免费大全短视频 | 精品一区二区电影 | 久久国产乱子伦精品 | 亚洲欧美不卡视频 | 蜜桃成品人免费视频 | 成人久久久精品国产乱码一区二区 | 国产精品无码久久久久 | 娇妻被各种姿势c到高潮小说 | 精品91av | 欧美三级一级 | 日本一区二区三区视频在线 | 久久我不卡 | 性少妇videosexfreexx入片 | 深夜视频福利 | 日韩在线观看视频一区 | 国产日韩线路一线路二 | 午夜精品福利视频 | 国产精品av久久久久久久久久 | 成人三级电影网址 | 新久草视频| 毛片免费在线视频 | 91精品国产九九九久久久亚洲 | 香蕉视频99 | 国产一级小视频 | 91精品动漫在线观看 | 99999久久久久久 | 欧美成人国产va精品日本一级 | 欧美四级在线观看 | 成人在线免费视频观看 | 今井夏帆av一区二区 | 91精品动漫在线观看 | 精品国产成人 | 18一20岁一级毛片 | 国产毛片aaa一区二区三区视频 |