sql中如何判断时间大小呢? 急!

2025-01-07 14:46:34
推荐回答(5个)
回答1:

时间要有单引号的,不然实际执行的是算术运算
select * From Book where EditionDate>(2001-1-1) 等同于
select * From Book where EditionDate>1999
1999可以隐式转换为日期,所以有结果。
正确写法是
select * From Book where EditionDate>'2001-1-1' and EditionDate<'2008-12-31'

回答2:

可以先转换成时间类型再比较撒
EditionDate>to_date('2001-1-1','yyyy-MM-dd') and EditionDate

回答3:

AND EditionDate > timestamp '2001-1-1'
AND EditionDate < = timestamp '2008-12-31'

回答4:

select * From Book where EditionDate>'2001-1-1' and EditionDate<'2008-12-31'

回答5:

select * From Book where EditionDate>(2001-1-1) or EditionDate<(2008-12-31)