资料来源:网络整理
时间: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

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。