+ -
当前位置:首页 → 问答吧 → sql语句 查询某一天数据每个小时的数据

sql语句 查询某一天数据每个小时的数据

时间:2011-09-20

来源:互联网

如何把数据库内的数据按时间统计,要求一天的24小时每个小时都要统计,然后分别输出,比如0时有多少数据,1时有多少数据这样,select count(1)
from line_movement_log a
where a.CARRIER_MVT_CNTR_INTERCHG_MD ='I'
and a.cntr_status = 'XF'
and a.tractor_gate_in_datetime ??,最后这个字段是时间,我用的是oracle数据库,请高手解答,谢谢

作者: xiewenping   发布时间: 2011-09-20

引用楼主 xiewenping 的回复:
如何把数据库内的数据按时间统计,要求一天的24小时每个小时都要统计,然后分别输出,比如0时有多少数据,1时有多少数据这样,select count(1)
from line_movement_log a
where a.CARRIER_MVT_CNTR_INTERCHG_MD ='I'
and a.cntr_status = 'XF'
and a.tractor_gate_in_datet……
ps:tractor_gate_in_datetime格式是这样的yyyy-mm-dd hh24:mi:ss

作者: xiewenping   发布时间: 2011-09-20

select to_char(a.tractor_gate_in_datetime, 'hh24'), count(1)
from line_movement_log a
where a.CARRIER_MVT_CNTR_INTERCHG_MD ='I'
and a.cntr_status = 'XF'
and trunc(a.tractor_gate_in_datetime) = trunc(sysdate)
group by to_char(a.tractor_gate_in_datetime, 'hh24');

作者: nGX20080110   发布时间: 2011-09-20

select count(1)
from line_movement_log a
where 你需要的条件
group by to_char(tractor_gate_in_datetime,'yyyy-mm-dd hh24')

作者: cocolmalu   发布时间: 2011-09-20

引用 2 楼 ngx20080110 的回复:
select to_char(a.tractor_gate_in_datetime, 'hh24'), count(1)
from line_movement_log a
where a.CARRIER_MVT_CNTR_INTERCHG_MD ='I'
and a.cntr_status = 'XF'
and trunc(a.tractor_gate_in_datetime) = tru……

有问题啊 !你的语句是统计每个小时的数据 和具体哪天没有关系啊。最多24条数据。

作者: cocolmalu   发布时间: 2011-09-20

看错了!你的只能统计当天的!漏看trunc(sysdate)了!

作者: cocolmalu   发布时间: 2011-09-20

引用 2 楼 ngx20080110 的回复:
select to_char(a.tractor_gate_in_datetime, 'hh24'), count(1)
from line_movement_log a
where a.CARRIER_MVT_CNTR_INTERCHG_MD ='I'
and a.cntr_status = 'XF'
and trunc(a.tractor_gate_in_datetime) = tru……

能不能在那个点为0的小时数也查询出来呢
比如,5点这个时间段统计的数据为0也显示出来

作者: xiewenping   发布时间: 2011-09-20

ORACLE的??建议去ORACLE去问问

作者: fredrickhu   发布时间: 2011-09-20

热门下载

更多