专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-683-0016      微信咨询  |  联系我们

oracle中查询某段日期内的某个时间段的语句

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/2/14 0:17:23       共计:3618 浏览
了解to_date ,to_char, trunc, group by 等相关知识

   查询表aaa中bbb在2011-8-22 至2011-8-25 中 每天10:00到11:00 内的数据 以及数目

select bbb ,count(bbb) from ( select * from aaa  where    rec_date between  trunc(to_date('2011-8-22 09:00:00','yyyy-mm-dd hh24:mi:ss')) and trunc(to_date('2011-8-25 09:00:00','yyyy-mm-dd hh24:mi:ss')) and  to_char( aaa.bbb, 'hh24:mi:ss') between '09:00:00' and'10:00:00') group  by bbb

如果是两个不同的表,确定其结构是否相同,使用union进行比较
select bbb ,count(bbb) from ( select * from aaa  where    rec_date between  trunc(to_date('2011-8-22 09:00:00','yyyy-mm-dd hh24:mi:ss')) and trunc(to_date('2011-8-25 09:00:00','yyyy-mm-dd hh24:mi:ss'))

union 

select * from aaa
where
to_char( aaa.bbb, 'hh24:mi:ss')between
 '09:00:00' and'10:00:00')

group  by bbb
版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:Oracle表时间区间查找 | ·下一条:oracle 数据太多 想只显示当前日期前三天的数据 条件语句怎么写呢?

Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有