mysql - mysql中的正则表达式来回答给定的查询
问题描述
我的 mysql 表有一个列结构,它转储由“;”分隔的各种属性 对于 html 文件的每个元素。
+-----------+------------------------------------+
| tag_id | attributes |
+-----------+------------------------------------+
| 1 |class:block_22;id:toc_id_35; |
| 2 |class:bloack_1000;id:12#4 |
+-----------+------------------------------------+
我想编写一个查询来选择具有
1.id attribute that starts with #
2.id attribute that ends with #
3.id attribute that has # in between
第一个查询可以这样回答
SELECT * FROM table where attributes like "%id:#%";
我不确定如何处理其他两个查询。请给我一些有价值的见解。
解决方案
这些模式应该做你想做的事:
where attribute regexp 'id:#'
where attribute regexp 'id:[^;]*#(;|$)'
where attribute regexp 'id:[^;]+#[^;]+'
推荐阅读
- r - 如何解决 R 中的 gplots 安装包问题?
- sharepoint - 如何在 SharePoint Online 中找到变体网站
- python - 如何仅在列表中循环某些单词(Python)
- c++ - 来自基本 ctor 的纯虚拟“非常 const”函数调用
- multithreading - 想要使用 Groovy 并行部署到服务器
- javascript - 如何使用Javascript在div标签可见时更改按钮标题
- python - 如何检查 pyomo 变量的索引
- javascript - particle.js 与 fullpage.js 冲突,阻止文本且未完全覆盖页面
- spring-integration - Spring Batch Remote Partitioning with Kafka 作为中间件
- sql - postgres 聚合中文本单元格之间的聚类/相似性