to_char 和 to_date 日期字段的比较

日期字段的比较

比如:查询2018-07-24的数据

--成功下发
select m.provincename,count(*) from (select *  from ms_mtmessage_a partition(part_20180724) union all select * from ms_mtmessage_b partition(part_20180724)) m,
(select * from ms_statusreport_a partition(part_20180724) union all select * from ms_statusreport_b partition(part_20180724)) s  
where m.mtmessageid = s.mtmessageid and to_char(m.sendtime,'yyyy-mm-dd hh24:mi:ss') >='2018-07-24 08:00:00' and
 to_char(m.sendtime,'yyyy-mm-dd hh24:mi:ss') <= '2018-07-24 09:00:00'and m.gatewayid=2 and s.statusreport = 'DELIVRD' and messagetype =4
  group by m.provincename order by m.provincename 
 
 --成功下发
select m.provincename,count(*) from (select * from ms_mtmessage_a  union all select * from ms_mtmessage_b) m,
(select * from ms_statusreport_a partition(part_20180724) union all select * from ms_statusreport_b partition(part_20180724)) s
where m.mtmessageid=s.mtmessageid and m.sendtime between to_date('2018-07-24 8:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2018-07-24 9:00:00','yyyy-mm-dd hh24:mi:ss')
 and m.gatewayid=2 and s.statusreport = 'DELIVRD' and messagetype=4 group by m.provincename order by m.provincename 
 
 --总下发
 select m.provincename, count(*)
  from (select *
          from ms_mtmessage_a partition(part_20180724)
        union all
        select * from ms_mtmessage_b partition(part_20180724)) m
where m.sendtime between to_date('2018-07-24 8:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2018-07-24 9:00:00','yyyy-mm-dd hh24:mi:ss')
 and m.gatewayid=2 and messagetype=4 group by m.provincename order by m.provincename

你可能感兴趣的:(神谕)