Fuzzy and accurate are opposite, but today I am not talking about what is a paradox. Let's look at the question below.
The database structure format is as follows:
Id | cid
--------------------------------
1 |, 4, 5, 7,
--------------------------------
3 |, 4, 5, 8,
--------------------------------
4 |, 5, 4,
--------------------------------
6 |, 5, 4, 7, 8,
--------------------------------
7 |, 8, 4, 5, 7, 9,
--------------------------------
8 |,
I 'd like to ask
If the cid values in my post are 4 and 5, how can I precisely query the data with id = 4?
Similarly, if the cid values in my post are 4, 5, 7, and 8, how can I precisely query this data with id = 6?
Note:
The data in the cid column is non-fixed and irregular. The only thing that can be confirmed is that the same value will not appear again.
In addition, I tried to use the like method and link method, which is not accurate enough. for example... where cid like '%, 4, %' and cid like '%, 5, %'
The solution is as follows:
He said that he was not as close to himself. He just made a mistake and the result was already coming.
I used three methods to perform the test. During the test, the data in the database is extracted 20000 times in a loop. The results are as follows:
SQL code
// 1770 ms ~ 1800 MS
Select id, type From hotel where type like '% | 21 | %' and type like '% | 101 | %' and LENGTH (type) = length ('| 21 | 101 | ')
SQL code
// 1760 ms ~ 1810 MS
Select id, type From hotel where locate ('| 21 |', type)> 0and locate ('| 101 |', type)> 0and LENGTH (type) = length ('| 21 | 101 | ')
SQL code
// The CPU is directly 100%, and the memory generator fails.
Select id, type From hotel where type REGEXP concat ('. * [', replace ('000000', '|'), ']. *')