当前位置:网站首页>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 !
边栏推荐
- AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务...
- None of the strongest kings in the monitoring industry!
- A novice asks a question. I am now deployed on a single machine. I submitted an SQL job and it runs normally. If I restart the service job, it will disappear and I will have to
- Cocoscreator+typescripts write an object pool by themselves
- dockermysql修改root账号密码并赋予权限
- 云原生(三十二) | Kubernetes篇之平台存储系统介绍
- 室内LED显示屏应该怎么选择?这5点注意事项必须考虑在内
- DockerMySQL无法被宿主机访问的问题解决
- GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
- DevSecOps软件研发安全实践——发布篇
猜你喜欢
Enterprises do not want to replace the old system that has been used for ten years
With the help of this treasure artifact, I became the whole stack
Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
js對JSON數組的增删改查
Use mitmproxy to cache 360 degree panoramic web pages offline
docker启动mysql及-eMYSQL_ROOT_PASSWORD=my-secret-pw问题解决
None of the strongest kings in the monitoring industry!
室内LED显示屏应该怎么选择?这5点注意事项必须考虑在内
Dockermysql modifies the root account password and grants permissions
Cloud native (32) | kubernetes introduction to platform storage system
随机推荐
Up to 5million per person per year! Choose people instead of projects, focus on basic scientific research, and scientists dominate the "new cornerstone" funded by Tencent to start the application
Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi
mysql连接vscode成功了,但是报这个错
cuda 探索
借助这个宝藏神器,我成为全栈了
云原生(三十二) | Kubernetes篇之平台存储系统介绍
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
NFTScan 开发者平台推出 Pro API 商业化服务
[launched in the whole network] redis series 3: high availability of master-slave architecture
Docker mysql5.7 how to set case insensitive
CSDN 上传图片取消自动加水印的方法
基于PaddlePaddle平台(EasyDL)设计的人脸识别课堂考勤系统
ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
Bipartite graph determination
With the help of this treasure artifact, I became the whole stack
面试题:AOF重写机制,redis面试必问!!!
Realize colorful lines and shape your heart
What does security capability mean? What are the protection capabilities of different levels of ISO?
机器人材料整理中的套-假-大-空话