当前位置:网站首页>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 !
边栏推荐
- Improving Multimodal Accuracy Through Modality Pre-training and Attention
- 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
- Let me ask you if there are any documents or cases of flynk SQL generation jobs. I know that flynk cli can create tables and specify items
- Is "applet container technology" a gimmick or a new outlet?
- docker启动mysql及-eMYSQL_ROOT_PASSWORD=my-secret-pw问题解决
- Two week selection of tdengine community issues | phase II
- DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
- How can Oracle CDC deserialize with jsondebeziumdeserializationschema
- 借助这个宝藏神器,我成为全栈了
- Children's pajamas (Australia) as/nzs 1249:2014 handling process
猜你喜欢

js對JSON數組的增删改查

Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi

C three ways to realize socket data reception

View
MySQL中正则表达式(REGEXP)使用详解
![[launched in the whole network] redis series 3: high availability of master-slave architecture](/img/42/e67c7fa88e57c8ad3262552fd7b83c.png)
[launched in the whole network] redis series 3: high availability of master-slave architecture

Modules that can be used by both the electron main process and the rendering process

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

Efficient ETL Testing
![[compilation principle] LR (0) analyzer half done](/img/ec/b13913b5d5c5a63980293f219639a4.png)
[compilation principle] LR (0) analyzer half done
随机推荐
面试题:AOF重写机制,redis面试必问!!!
Devsecops software R & D security practice - release
docker mysql5.7如何设置不区分大小写
spark调优(二):UDF减少JOIN和判断
flinksql select id ,count(*) from a group by id .
mysql连接vscode成功了,但是报这个错
How to choose indoor LED display? These five considerations must be taken into account
None of the strongest kings in the monitoring industry!
docker启动mysql及-eMYSQL_ROOT_PASSWORD=my-secret-pw问题解决
让 Rust 库更优美的几个建议!你学会了吗?
Why are some people still poor and living at the bottom of society even though they have been working hard?
The problem that dockermysql cannot be accessed by the host machine is solved
mysql拆分字符串作为查询条件的示例代码
COSCon'22 社区召集令来啦!Open the World,邀请所有社区一起拥抱开源,打开新世界~
mysql-cdc 的jar包 ,在flink运行模式下,是不是要放在不同的地方呢?
What can be done for traffic safety?
The statement that allows full table scanning does not seem to take effect set odps sql. allow. fullscan=true; I
食品里的添加剂品种越多,越不安全吗?
[step on pit collection] attempting to deserialize object on CUDA device+buff/cache occupy too much +pad_ sequence
How to choose the server system