select uid from T_TABLE Where num='3' and time between like '200701%' and like '200702%'

来源:百度知道 编辑:UC知道 时间:2024/06/10 16:15:37
select uid from T_TABLE Where num='3' and time between like '200701%' and like '200702%'
我这条语句有错,请各位写出正确查询
本意是查uid,条件是 num=3 和 时间time 在2007年1月 到 2007年2月 之间
between和like是不是不能一起用,怎么查好呢?
我的time字段是精确到秒的,所以要提出月份的
我的数据库不是SQL SERVER的
谢谢你的回答,期待更准确的答案

直接限定time在1月和2月不就可以了?
select uid from T_TABLE Where num='3' and time >= '20070101' and time<'20070301'
这样选出的数据是1月2月的。
当然也可以把time字段转换一下(针对SQL SERVER有效,其它数据库可能不行),不过这样影响性能,数据量大的时候不推荐。
select uid from T_TABLE Where num='3' and convert(varchar(8),time,112) like '20070[12]%'