sql select的问题
来源:百度知道 编辑:UC知道 时间:2024/05/27 09:11:53
假设表如下
id name
100100 aaa
100101 bbb
100102 ccc
100200 ddd
100201 eee
100202 fff
需要选择ID前4位是1001的,或者前4位是1002这样的,怎么写查询语句?
id name
100100 aaa
100101 bbb
100102 ccc
100200 ddd
100201 eee
100202 fff
需要选择ID前4位是1001的,或者前4位是1002这样的,怎么写查询语句?
数值型: where 100100<=ID<100200
字符型: where ID like '1001%'
select * from table2223131 where id between 100100 and 100299
Select * From [表名] Where LEFT(ID,4) = 1001 Or LEFT(ID,4) = 1002
这里面用到了LEFT来取从左数第四位~`
OR后面是第二个条件~`自己酌情修改下
使用通配符%
select * from yourtable
where
(id like '1001%')
or
(id like '1002%')