当前位置:网站首页>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 !
边栏推荐
- 【全网首发】Redis系列3:高可用之主从架构的
- 这个『根据 op 值判断操作类型来自己组装 sql』是指在哪里实现?是指单纯用 Flink Tabl
- Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
- MySQL authentication bypass vulnerability (cve-2012-2122)
- 不要再说微服务可以解决一切问题了
- [unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
- flinksql select id ,count(*) from a group by id .
- CRMEB商城系统如何助力营销?
- Enterprises do not want to replace the old system that has been used for ten years
- Station B Big utilise mon monde pour faire un réseau neuronal convolutif, Le Cun Forward! Le foie a explosé pendant 6 mois, et un million de fois.
猜你喜欢

Introduction to network basics

Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million

Hard core observation 545 50 years ago, Apollo 15 made a feather landing experiment on the moon

With the help of this treasure artifact, I became the whole stack

js对JSON数组的增删改查

European Bioinformatics Institute 2021 highlights report released: nearly 1million proteins have been predicted by alphafold

浅谈现在的弊端与未来的发展

Enterprises do not want to replace the old system that has been used for ten years

借助这个宝藏神器,我成为全栈了

为了交通安全,可以做些什么?
随机推荐
How to choose indoor LED display? These five considerations must be taken into account
企業不想換掉用了十年的老系統
儿童睡衣(澳大利亚)AS/NZS 1249:2014办理流程
使用MitmProxy离线缓存360度全景网页
Is the more additives in food, the less safe it is?
(flutter2) as import old project error: inheritfromwidgetofexacttype
Some suggestions for foreign lead2022 in the second half of the year
CUDA exploration
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
Nftscan Developer Platform launches Pro API commercial services
动作捕捉用于蛇运动分析及蛇形机器人开发
AcWing 4299. Delete point
MySQL中正则表达式(REGEXP)使用详解
Graphite document: four countermeasures to solve the problem of enterprise document information security
Pytest unit test series [v1.0.0] [pytest execute unittest test case]
mysql-cdc 的jar包 ,在flink运行模式下,是不是要放在不同的地方呢?
(1) Chang'an chain learning notes - start Chang'an chain
石墨文档:4大对策解决企业文件信息安全问题
Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~