日期:2014-05-16  浏览次数:21396 次

sql 大于等于生效时间并且失效时间不为空的话小于等于失效时间
我现在有一张表 有生效时间和失效时间字段 
我要查询的条件是时间大于等于生效时间并且失效时间不为空的话小于等于失效时间
主要是“并且失效时间不为空的话小于等于失效时间”这点怎么做

------解决方案--------------------
引用:
我现在有一张表 有生效时间和失效时间字段 
我要查询的条件是时间大于等于生效时间并且失效时间不为空的话小于等于失效时间
主要是“并且失效时间不为空的话小于等于失效时间”这点怎么做


空的话怎么处理?
------解决方案--------------------
引用:
我现在有一张表 有生效时间和失效时间字段 
我要查询的条件是时间大于等于生效时间并且失效时间不为空的话小于等于失效时间
主要是“并且失效时间不为空的话小于等于失效时间”这点怎么做



select * from 表 

where  getdate() between '生效时间' and isnull('失效时间','--@@@--')----@@@--要是空的需要看到,这里就写'9999-99-99',否则'0000-00-00'



------解决方案--------------------

select * from table
where sysdate >= start_time
and ((sysdate <= end_time and end_time is not null) or end_time is null)

--start_time生效时间 end_time失效时间

------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

我现在有一张表 有生效时间和失效时间字段 
我要查询的条件是时间大于等于生效时间并且失效时间不为空的话小于等于失效时间
主要是“并且失效时间不为空的话小于等于失效时间”这点怎么做



select * from 表 

where  getdate() between '生效时间' and isnull('失效时间','--@@@--')----@@@--要是空的需要看到,这里就写'9999-99-99',否则'0000-00-00'



oracle 好像没 isnull  用decode判断吗



------解决方案--------------------
你用union all 好了 还快点
------解决方案--------------------
引用:
Quote: 引用:

你用union all 好了 还快点

想了一会儿 发现方法有很多  不过union all 写起来太长了 还是用decode解决了 
不过说起来decode到底有多慢呢


看数据量啦~~慢的话就再想别的办法喽!