当前位置:网站首页>mysql 查询某字段中以逗号分隔的字符串的方法
mysql 查询某字段中以逗号分隔的字符串的方法
2022-07-24 16:57:00 【ILHONG】
mysql 查询某字段中以逗号分隔的字符串的方法
文章目录
前言
现在有如下场景。我们有一个案例表。每一个案例对应多个标签,一个标签对应一个案例。我们在前台做分页的时侯,需要对多个标签进行与匹配
表数据结构如下
一、首先讲一个需求
需要查出crowd_label_id 为 4,6,9的所有case_id 4,6,9为与条件
- 首先查询出对应case_id所有满足的标签 也就是行转列 使用
GROUP_CONCAT函数
- 查询出来后我们就知道对应的case_id所有的标签。
- 剩下就是如果根据label_id去做匹配了。这时候我们可以用到mysql函数
FIND_IN_SET来匹配字符串中是否存在指定的标签。当然这一步也可以放到程序中去做判断。
结果上面完美匹配了label_id包含4,9的所有case_id
附上sql
SELECT * FROM (
SELECT case_id,GROUP_CONCAT(crowd_label_id) AS aa FROM weapp_case_label WHERE crowd_label_id IN (4,6,9) GROUP BY case_id
) AS aaa WHERE FIND_IN_SET('4', aa) AND FIND_IN_SET('9', aa)
总结
这里主要的知识点是mysql的行转列,有多行数据如果拼成一列去展示出来。
边栏推荐
- ZCMU--5023: 家庭划分(C语言)
- What does Baidu promote "delete and recall" mean?
- [zero basis] fully understand webgl (VIII)
- Solve the timeliness problem caused by Eureka's default cache configuration
- How vscode mouse wheel enlarges the interface
- regular expression
- OS Experiment 5 process switching based on kernel stack switching
- Causes and solutions of QT signal and slot connection failure
- Wechat applet list (list rendering of data rendering)
- QT embed Notepad under win10
猜你喜欢

Still shocked by the explosion in the movie? Then you must not miss this explosive plug-in of unity

QT generation connection Library

Axi protocol (2): five channels and two transactions of Axi architecture

Long awaited full platform support - Open Source im project uniapp update of openim

Kernel development

OS Experiment 5 process switching based on kernel stack switching

IP day 13 notes

SS-Paper【1】:Fully Convolutional Networks for Semantic Segmentation

Comparison of array and object merging methods assign, merge, defaults, defaultsdeep in lodash
ShardingSphere数据库读写分离
随机推荐
数字化转型一定要有数字化思想
Getting started with ARP
IP的概念,IP的分类,IP复用技术
AXI协议(2):AXI架构的五个通道和两种事务
Axi protocol (3): handshake mechanism and implementation details of Axi architecture
How vscode mouse wheel enlarges the interface
Parental delegation mechanism
【时序逻辑电路】——计数器
1184. Distance between bus stops
JUC source code learning note 3 - AQS waiting queue and cyclicbarrier, BlockingQueue
Buffer overflow vulnerability lab experiment record
DBF menu driver: librarydatabaseproject
会议OA项目进度(二)
Cross server, insert, search
With notes: printing order of synchronous, asynchronous, micro task and macro task
EF combined with sqlbulkcopy batch insert data
804. Unique Morse code word
Zcmu--5083: number pairs of ly (C language)
Jing Wei PS tutorial: basic part a
Interview question 01.02. determine whether it is character rearrangement
