SQL中查询条件
来源:百度知道 编辑:UC知道 时间:2024/09/21 09:32:30
列属性是字符形
输入号有110、210、1066、2100
使用select * from blh where blh>='1066' and blh<='2100'
会把所有的号查出来,怎么只查出1066和2100
输入号有110、210、1066、2100
使用select * from blh where blh>='1066' and blh<='2100'
会把所有的号查出来,怎么只查出1066和2100
先转成数值型,
select *
from blh
where convert(blh as int) >= 1066
and convert(blh as int) <= 2100
select * from blh where blh='1066' or blh ='2100'
或
select * from blh where blh in ('1066' ,'2100')
用程序或写个存储过程把要查的放临时表里
通过
where blh in (select id from 临时表)
子查询判断不管你要查的有多少都会方便些
判断查询后直接清空临时表就可以了
1066和2100加了单引号后就变成了字符串了
当然不能比较大小了 只能比较是否为同样(=)
去掉那个引号
select min(列属性名),max(列属性名) from blh
应该用between and