当前位置:网站首页>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 !
边栏推荐
- 浅谈现在的弊端与未来的发展
- mysql-cdc 的jar包 ,在flink运行模式下,是不是要放在不同的地方呢?
- What does front-end processor mean? What is the main function? What is the difference with fortress machine?
- [unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
- B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
- ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
- ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
- GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
- Flutter life cycle
- Devsecops software R & D security practice - release
猜你喜欢
借助这个宝藏神器,我成为全栈了
js對JSON數組的增删改查
View
儿童睡衣(澳大利亚)AS/NZS 1249:2014办理流程
Introduction to network basics
Koa2 addition, deletion, modification and query of JSON array
Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
With the help of this treasure artifact, I became the whole stack
AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务...
#DAYU200体验官# 在DAYU200运行基于ArkUI-eTS的智能晾晒系统页面
随机推荐
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
企业不想换掉用了十年的老系统
Automatically update selenium driver chromedriver
Efficient ETL Testing
How can Oracle CDC deserialize with jsondebeziumdeserializationschema
AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务...
允许全表扫描 那个语句好像不生效set odps.sql.allow.fullscan=true;我
AcWing 4299. Delete point
mysql查看表结构的三种方法总结
每人每年最高500万经费!选人不选项目,专注基础科研,科学家主导腾讯出资的「新基石」启动申报...
Dockermysql modifies the root account password and grants permissions
Efficient ETL Testing
[step on pit collection] attempting to deserialize object on CUDA device+buff/cache occupy too much +pad_ sequence
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
Devsecops software R & D security practice - release
AcWing 4300. Two operations (minimum number of BFS searches)
欧洲生物信息研究所2021亮点报告发布:采用AlphaFold已预测出近1百万个蛋白质
How does crmeb mall system help marketing?
Precise drag and drop within a contentable
UE4 blueprint learning chapter (IV) -- process control forloop and whileloop