我正在尝试使用一系列数字从表中选择数据。总之,我想选择数字在6到9范围内的路径
$sql = "select * from users where path_name like between '%6%' and '%9%' ";
但没有任何回报。
任何人都有更好的方法吗?
答案 0 :(得分:2)
您不需要like
如果您想返回6
和9
之间的所有数字:
$sql = "select * from users where path_name between 6 and 9";
答案 1 :(得分:1)
这就是我在寻找的人
$sql1 = "select * from users where path_name REGEXP '[6-9]'";
参考
Regular expressions
答案 2 :(得分:0)
由于path_name是数字,您应该使用条件语句。考虑使用where path_name >= 6 and path_name <= 9
或更简单的5和10,条件很好。
答案 3 :(得分:0)
SELECT * FROM USERS
WHERE SUBSTR(PATH_NAME, 4, len(PATH_NAME)-4) BETWEEN 6 and 9
我想你的path_name值就像'axr6b'
答案 4 :(得分:0)
如果是SQL Server,则范围匹配可以使用Like
declare @users table (path_name varchar(10))
insert @users values
('download1'), ('download3'), ('download5'), ('download6'),
('download7'), ('download9'), ('download10')
select * from @users where path_name like '%[6-9]%'