您的位置:首页 > 数据库 > Oracle

oracle时间段间数据查询(须修改)

2012-09-09 20:12 211 查看
时间段间数据查询

//返回当天的数据

select d.device_name as 设备,d.alert_time 时间 from device d where d.alert_time

between to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd hh24:mi:ss')and

sysdate;

--按照每月进行统计

select to_char(sysdate,'mm') from dual group by to_char(sysdate,'mm')

--按照每季度进行统计

select to_char(sysdate,'q') from dual group by to_char(sysdate,'q')

--按照每周度进行统计

select to_char(sysdate,'ww') from dual group by to_char(sysdate,'ww')

--按照每年进行统计

select to_char(sysdate,'yyyy') from dual group by to_char(sysdate,'yy')

获取某一天的数据

select d.device_name as 设备,d.alert_time 时间 from device d where d.alert_time

between to_date('2010-9-27 00:00:00','yyyy-mm-dd hh24:mi:ss') and

to_date('2010-9-27 23:59:59','yyyy-mm-dd hh24:mi:ss')

Oracle查询时间段为两条语句:between……and……或>=……,<=……

1.between……and……

实例:

select * from location t

where locationdate

Between to_date('2010-5-4 10:00:00','yyyy-mm-dd hh24:mi:ss')

And to_date('2010-5-4 15:00:00','yyyy-mm-dd hh24:mi:ss')

order by locationdate desc

2.>=……,<=……

实例:

select t.* from location t

where locationdate>=to_date('2010-5-4 10:00:00','yyyy-mm-dd hh24:mi:ss')

and locationdate<=to_date('2010-5-4 15:00:00','yyyy-mm-dd hh24:mi:ss')

order by locationdate desc
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: