当前位置:网站首页>MySQL implementation of field segmentation from one line to multiple lines of example code
MySQL implementation of field segmentation from one line to multiple lines of example code
2022-07-06 23:20:00 【1024 questions】
Let's look at the data structure first , I have few fields here , Only the most important part


According to what we learned last time LEFT() Function to group
SELECT LEFT(provinces,6),COUNT(1) FROM `region_map_copy` GROUP BY LEFT(provinces,6)The result is as follows :

This effect is not what we want , We want to 210000 All are merged
Use SUBSTRING_INDEX(),LEFT() These two functions , In Canada help_topic This table
help_topic: Split by character , One line to many lines
SELECT COUNT(*), SUBSTRING_INDEX( SUBSTRING_INDEX( a.provinces, ',', b.help_topic_id + 1 ), ',',- 1 ) AS ids FROM `region_map_copy` AS a JOIN mysql.help_topic AS b ON b.help_topic_id < ( LENGTH( a.provinces ) - LENGTH( REPLACE ( a.provinces, ',', '' ) ) + 1 ) GROUP BY (SUBSTRING_INDEX( SUBSTRING_INDEX( a.provinces, ',', b.help_topic_id + 1 ), ',',- 1 ) )give the result as follows :

Got what we wanted
mysql Field interception function :
left( Field name ,index) Start from the left index Began to intercept
right( Field name ,index) Start from the right index Began to intercept
substring( Field name ,index) When index>0 From the left to the end When index<0 From the right to the end When index=0 Returns an empty
substring( Field name ,index,len) from index Start , Intercept len length
substring_index( Field name ,str,count),str Is the intercepted field count Where does it start (0 From the left, the second 0 Start ,-1 Start first on the right )
Be careful : This way does not support mariadb
Add : Look at the below MySql The fields in the database table are separated by commas , Field for conditional query
select p.* from t_project_info p
select p.*from t_project_info pwhere FIND_IN_SET(6,p.thematic_library_ids)
This is about MySQL Implement field segmentation ( One line to many lines ) This is the end of the article , More about mysql Please search the previous articles of SDN or continue to browse the relevant articles below. I hope you will support SDN more in the future !
边栏推荐
- How to achieve text animation effect
- (1)长安链学习笔记-启动长安链
- B站大佬用我的世界搞出卷積神經網絡,LeCun轉發!爆肝6個月,播放破百萬
- (shuttle) navigation return interception: willpopscope
- (flutter2) as import old project error: inheritfromwidgetofexacttype
- mysql查看表结构的三种方法总结
- Realize colorful lines and shape your heart
- (DART) usage supplement
- View
- Precise drag and drop within a contentable
猜你喜欢

不要再说微服务可以解决一切问题了

Children's pajamas (Australia) as/nzs 1249:2014 handling process

【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件

动作捕捉用于蛇运动分析及蛇形机器人开发

GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议

js對JSON數組的增删改查

为了交通安全,可以做些什么?

Let's see through the network i/o model from beginning to end

室内LED显示屏应该怎么选择?这5点注意事项必须考虑在内

AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务...
随机推荐
不要再说微服务可以解决一切问题了
B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
Les entreprises ne veulent pas remplacer un système vieux de dix ans
(1) Chang'an chain learning notes - start Chang'an chain
Graphite document: four countermeasures to solve the problem of enterprise document information security
云原生(三十二) | Kubernetes篇之平台存储系统介绍
「小程序容器技术」,是噱头还是新风口?
服务器的系统怎么选者
同一个作业有两个source,同一链接不同数据库账号,为何第二个链接查出来的数据库列表是第一个账号的
借助这个宝藏神器,我成为全栈了
ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
Docker starts MySQL and -emysql_ ROOT_ Password = my secret PW problem solving
Is the more additives in food, the less safe it is?
存币生息理财dapp系统开发案例演示
MySQL connected vscode successfully, but this error is reported
The statement that allows full table scanning does not seem to take effect set odps sql. allow. fullscan=true; I
Is "applet container technology" a gimmick or a new outlet?
Case recommendation: An Qing works with partners to ensure that the "smart court" is more efficient
机器人材料整理中的套-假-大-空话
NFTScan 开发者平台推出 Pro API 商业化服务