从字符串mysql中检索数字

时间:2022-03-31 00:32:08

I've got a mysql database containing table "numbers" and entries

我有一个包含表“数字”和条目的mysql数据库

id | numberss
1 | 1,5,45
2 | 11,8,99
3 | 14, 15,84
4 | 1,58,47

How I have to write a mysql query, to retreive info only from those tables, which got number "1" in field "numberss" ? Not 11, not 15, only 1. Now I have:

我如何编写一个mysql查询,仅从那些表格中“数字”中得到数字“1”的表中检索信息?不是11,不是15,只有1.现在我有:

mysql_query("SELECT * FROM numbers WHERE numberss LIKE '%1%'"); 

But of course it doesn't work how I want to...

但当然它不起作用,我想...

2 个解决方案

#1


3  

SELECT * FROM numbers WHERE FIND_IN_SET(1, numberss);

#2


0  

SELECT * FROM numberss WHERE numberss 
LIKE  '%[^0-9]1[^0-9]%' 
or numberss like '1[^0-9]%'  
or numberss like '%[^0-9]1'

should work

应该管用

#1


3  

SELECT * FROM numbers WHERE FIND_IN_SET(1, numberss);

#2


0  

SELECT * FROM numberss WHERE numberss 
LIKE  '%[^0-9]1[^0-9]%' 
or numberss like '1[^0-9]%'  
or numberss like '%[^0-9]1'

should work

应该管用