午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:36日期:2023-10-10 09:14:51

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

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

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

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

select s.`name` as shopname,a.account_id from shops sinner 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相同合并成一行,以逗號隔開

//這兩個是網上的例子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 sinner 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將一個字段中以逗號分隔的取出來形成新的字段實現

第二種方法

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

[Product] -- 該字段存儲格式為 7,8,9,11,10,12 ,數據類型為nvarcharselect 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字段逗號分隔內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: MySQL 數據庫
相關文章:
主站蜘蛛池模板: 二级毛片视频 | 欧美在线日韩 | 亚洲乱亚洲乱妇 | 欧美gv在线观看 | 欧美成人三级在线 | 黄色三级小视频 | 成人免费观看视频 | 亚洲欧美自偷自拍 | 91爱爱网站 | 国产精品一区二区不卡 | 久久精品99国产国产精 | 天堂av免费在线 | 免费在线黄色网 | 天天操综合网 | 激情四射av| 欧美一级精品 | 亚洲免费a | 视频在线一区二区 | 国产91在线播放精品91 | 黄色a一级 | 黄色av大全 | 欧美黄色大片免费看 | 在线免费小视频 | 337p粉嫩大胆色噜噜噜 | 好吊色视频在线观看 | 永久av免费网站 | 第一av网 | 91福利影院 | 91成人精品一区在线播放 | 四虎影视一区二区 | 天堂а√在线中文在线鲁大师 | 国产精品99久久久久久动医院 | 欧美精品久久久久久久久老牛影院 | 欧美日韩在线播放视频 | 色大师在线观看 | 久久嫩草捆绑紧缚 | 精品久久久网站 | 欧美午夜精品 | 亚洲高潮 | 国产一区二区三区在线观看视频 | 欧美一级片免费观看 |