当前位置:网站首页>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 !
边栏推荐
- Demonstration of the development case of DAPP system for money deposit and interest bearing financial management
- Bipartite graph determination
- Realize colorful lines and shape your heart
- [untitled]
- 欧洲生物信息研究所2021亮点报告发布:采用AlphaFold已预测出近1百万个蛋白质
- Dockermysql modifies the root account password and grants permissions
- 问下各位,有没有flink sql生成作业的文档啊或是案列啊知道flink cli可以建表和指定目
- Let's see through the network i/o model from beginning to end
- Pdf batch splitting, merging, bookmark extraction, bookmark writing gadget
- MySQL authentication bypass vulnerability (cve-2012-2122)
猜你喜欢
Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
Pdf batch splitting, merging, bookmark extraction, bookmark writing gadget
[compilation principle] LR (0) analyzer half done
Improving Multimodal Accuracy Through Modality Pre-training and Attention
浅谈网络安全之文件上传
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
DockerMySQL无法被宿主机访问的问题解决
On file uploading of network security
Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi
Why are some people still poor and living at the bottom of society even though they have been working hard?
随机推荐
Redis 持久化机制
How can Oracle CDC deserialize with jsondebeziumdeserializationschema
CRMEB商城系统如何助力营销?
js对JSON数组的增删改查
mysql拆分字符串作为查询条件的示例代码
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~
Enterprises do not want to replace the old system that has been used for ten years
Efficient ETL Testing
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
Case recommendation: An Qing works with partners to ensure that the "smart court" is more efficient
ICLR 2022 | pre training language model based on anti self attention mechanism
Children's pajamas (Australia) as/nzs 1249:2014 handling process
监控界的最强王者,没有之一!
C three ways to realize socket data reception
js對JSON數組的增删改查
Huawei cloud gaussdb (for redis) unveils issue 21: using Gauss redis to achieve secondary indexing
Pytest unit test series [v1.0.0] [pytest execute unittest test case]
Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
Hard core observation 545 50 years ago, Apollo 15 made a feather landing experiment on the moon