Sybase中SQL关于时间的模糊查询,高手请进(急)!

2025-01-02 17:24:32
推荐回答(3个)
回答1:

如果TIME是datetime数据类型:

select * from A where datepart(year,TIME) = 2101 and datepart(month,TIME) = 2
或者
select * from A where TIME between "2010-2-1" and "2010-2-28 23:59:29"

如果TIME是字符类型
select * from A where TIME between "20100201" and "20100228"

回答2:

where TIME >='2010-2-1' and TIME <'2010-3-1'

或者

where year(TIME)=2010 and month(TIME)=2

-------------------------------------
时间类型转换为字符型用like 效率会低哦

如果TIME是datetime型的
where convert(varchar,TIME,112) like '201002%'

如果TIME是字符型的
where TIME like '201002%'

回答3:

select * from 表A where to_char(time,'YYYYMM') like '%201002%'