请教这样的SQL语句怎么写

来源:百度知道 编辑:UC知道 时间:2024/06/08 07:20:30
在N条数值型记录中筛选满足条件第1-2位是从10-38之间的数字
第5位是3-4或者是7的数字

比如:
1211111
1033324
1922225
4233331
3712227
最后结果:
1033324
3712227

这样的需求怎样用1条SQL语句实现

select *
from table
where left(Num,2) between 10 and 38
and Num like '____[347]%'

select * from table_name where substring(字段名,1,2) between 10 and 38
and substring(字段名,5,1) in (3,4,7)

你条件应该是第1-2位是10-38并且第5为是3-4或7

-----------------------------
不对啊,你这个结果3712227不满足第5位是3-4或7啊?

你的1-2位是从左向右数的么?

SELECT * FROM 表 WHERE SUBSTR(TO_CHAR(字段),1,2) BETWEEN '10' AND '38' AND SUBSTR(TO_CHAR(字段),5,1) IN('3','4','7');

select * from 表名 where substring(字段名,1,2) between '10' and '38' and substring(字段名,7,1) in (3,4,7)

//如果字段是int,10和38可以不用引号引起来

slect num from theTable
where str(num,2) between 10 and 38
and substr(num,5,1) IN('3','4','7');