我的数据库设计是:有一个日期的字段“myDate”是字符型,存储格式是:“2009-11-18”,还有一个字段是“myTime”也是字符型,存储格式是:“01:00:00”,每个小时一条数据,是24小时制的。
现在的问题是:我想查询一段日期,一段时间的数据。例如:日期2009-11-01到2009-11-18;时间20:00:00到02:00:00,这样的SQL语句怎么写。请不吝指教!
现在的问题是:我想查询一段日期,一段时间的数据。例如:日期2009-11-01到2009-11-18;时间20:00:00到02:00:00,这样的SQL语句怎么写。请不吝指教!
where datecol||timecol between '2009-11-01' and '2009-11-18'
and (timecol>='20:00:00' or timecol<='02:00:00')
select * from table1
where datecol between '2009-11-01' and '2009-11-18'
and (timecol>='20:00:00' or timecol <='02:00:00')
如果是直接date between to_date('2009-11-01 20:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2009-11-18 02:00:00','yyyy-mm-dd hh24:mi:ss')现在可以 to_date(myDate||' '||myTime,'yyyy-mm-dd hh24:mi:ss') between to_date('2009-11-01 20:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2009-11-18 02:00:00','yyyy-mm-dd hh24:mi:ss')
datecol between '2009-11-01' and '2009-11-01'
and timecol>='02:00:00' and timecol <='08:00:00'
以24点为界限的
根据你要求的时段不同使用的连接词也就不同了
一个用or 一个用and