在MYSQL中查找另一個字符串

[英]Find a string inside an other in MYSQL


I have this code.

我有這個代碼。

SELECT
`realestates`.`ID`,
`realestates`.`Code`
FROM
`realestates`
WHERE INSTR('S47ES35ES12E',('S' + realestates.ID + 'E'));

I have a realestates table like this.

我有這樣的房地產表。

ID Code    
1  4671    
2  4890    
...    
12  5031    
...    
34  5033    
35  6060    
36  6061    
...    
47  7011   
48  7012   
... 
147 8000    
148 8101

How can I change it so, it would find the realestate only with ID 47, ID 35 and ID 12? Because now I have a bunch of records. It looks like my 'S' and 'E' strings are completely ignored so it finds all those records that has 47 in their ID number somewhere so this can result ID 147 and ID 47 as well.

我怎樣才能更改它,它只能找到ID 47,ID 35和ID 12的房地產?因為現在我有一堆記錄。看起來我的'S'和'E'字符串被完全忽略,所以它找到所有那些在其ID號中有47個的記錄,這樣就可以得到ID 147和ID 47。

This "my favourites" string 'S47ES35ES12E' is a list of preselected real estates. I just want to print them on one page but my code pulls in other real estates as well who are actually not in this "my favourites" string.

這個“我最喜歡的”字符串'S47ES35ES12E'是一個預選的房地產列表。我只是想在一個頁面上打印它們,但我的代碼也會吸引其他房地產,而實際上並不在這個“我最喜歡的”字符串中。

1 个解决方案

#1


1  

WHERE  'S47ES35ES12E' LIKE concat('%S', realestates.ID, 'E%')

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/09/02/1876b8d0c3725a0e22e4564dbda927e9.html



 
  © 2014-2022 ITdaan.com 联系我们: