[英]a table of occurances of pattern in an SQL table field
我有這張桌子
文本
| txt_id | txt_content |
|--------+----------------------------------------------|
| 1 | A ton of text and <<this>> |
| 2 | More text <<and>> that |
| 3 | <<Very>> much <<text>> enough for<everyone>> |
還有這張桌子
標簽
| tag_id | tag_name |
|--------+----------|
| 1 | THIS |
| 2 | AND |
| 3 | VERY |
| 4 | TEXT |
| 5 | EVERYONE |
我需要一個查詢來生成此表。
| txt_id | tag_id |
|--------+--------|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 3 | 4 |
| 3 | 5 |
通過單獨獲取每個文本片段來使用python代碼是有動機的,但是文本表具有很多行(> 30M),並且我認為在數據庫后端通信上會花費很多時間。 有沒有辦法用MySQL做這種事情? 我什至會滿意
| txt_id | tag_id |
|--------+----------|
| 1 | this |
| 2 | and |
| 3 | Very |
| 3 | text |
| 3 | everyone |
但是我希望最后一部分在MySQL中很容易做到。
這並不需要特別快 ,但是它將滿足您的要求:
select t.txt_id, ta.tag_id
from text t join
tags ta
on t.txt_content like concat('%<', ta.tag_name, '>%');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.