求一条查询语句 郁闷中...
时间:2011-11-29
来源:互联网
start_date_time stop_date_time
2002-01-28 14:55:00 2002-02-07 13:44:26
2002-01-28 14:55:00 2002-02-09 9:53:00
2002-01-28 14:55:00 2002-02-09 9:53:00
2002-01-28 14:55:00 null
2002-01-28 14:55:00 2002-02-09 9:53:00
2002-01-28 14:55:00 2002-02-09 9:53:00
2002-01-28 14:55:00 2002-02-09 9:53:00
2002-01-28 14:55:00 2002-02-09 9:53:00
2.查询语句 :
传入参数:例如 2001-01-30 只传入当天的日期不包括时间,
要求:1.查询出 start_date_time < 传入参数(2001-01-30 )> stop_date_time 数据
如果:stop_date_time 为空时,只考虑条件 start_date_time < 传入参数(2001-01-30 )
请大家帮忙分析这个查询语句怎么写
作者: david_anwei 发布时间: 2011-11-29
作者: david_anwei 发布时间: 2011-11-29
作者: scrack 发布时间: 2011-11-29
start_date_time < 传入参数(2001-01-30 )> stop_date_time 数据 stop_date_time 为空时,只考虑条件 start_date_time < 传入参数(2001-01-30 ) select * from table1 where case when stop_date_time is null then trunc(start_date_time,'mm')<trunc('2000-01-30','mm') and trunc(stop_date_time,'mm')<trunc('2000-01-30','mm') else trunc(start_date_time,'mm')<trunc('2000-01-30','mm') end
作者: cosio 发布时间: 2011-11-29
作者: programmerxiaocai 发布时间: 2011-11-29
select * from tb where (stop_date_time is null or stop_date_time<to_date('2001-01-30','yyyy-mm-dd')) and start_date_time<to_date('2001-01-30','yyyy-mm-dd')
作者: lxpbs8851 发布时间: 2011-11-29
select *from tb where case when stop_date_time is null then start_date_time<to_date('2001-01-30','yyyy-mm-dd') else stop_date_time<to_date('2001-01-30','yyyy-mm-dd') end
作者: xpingping 发布时间: 2011-11-29
select * from ORDERS
where case when stop_date_time is null then trunc(start_date_time,'yyyy-mm-dd') < trunc('2000-01-30','yyyy-mm-dd') else trunc(start_date_time,'yyyy-mm-dd') < trunc('2000-01-30','yyyy-mm-dd') and trunc(stop_date_time,'yyyy-mm-dd') < trunc('2000-01-30','yyyy-mm-dd') end
红色标示处 MISSING KEYWORD
作者: david_anwei 发布时间: 2011-11-29
select start_date_time,to_date(start_date_time,'yyyy-mm-dd') from ORDERS
查询结果:
1 2002-01-28 14:55:00 0028-01-02
2 2002-01-28 14:55:00 0028-01-02
3 2002-01-28 14:55:00 0028-01-02
4 2002-01-28 14:55:00 0028-01-02
5 2002-01-28 14:55:00 0028-01-02
作者: david_anwei 发布时间: 2011-11-29
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28