表A字段1为自增主键
字段2为车辆ID(可重复)
字段3为车辆工作工作小时
车辆4为车辆开始工作时间
车辆5为车辆结束工作时间要求1:
给出一个车辆ID(比如001)和日期范围(比如2012-8-1到2012-8-10),统计这辆车在每天的工作小时数,最终的效果的
车辆ID 车辆工作小时 日期
001 2小时 2012-8-1
001 3小时 2012-8-2
001 1小时 2012-8-3
...
字段2为车辆ID(可重复)
字段3为车辆工作工作小时
车辆4为车辆开始工作时间
车辆5为车辆结束工作时间要求1:
给出一个车辆ID(比如001)和日期范围(比如2012-8-1到2012-8-10),统计这辆车在每天的工作小时数,最终的效果的
车辆ID 车辆工作小时 日期
001 2小时 2012-8-1
001 3小时 2012-8-2
001 1小时 2012-8-3
...
解决方案 »
- WMSYS.WM_CONCAT 函数的详细说明,哪位高人晓得?
- sqlldr导入数据的问题
- pl/sql的幫助文檔問題
- alter table t move tablespaces 应该注意的地方
- 请教一个问题:想写个存储过程统计连续7天字段RSSI_avg_m超过-95的数据
- orcl中 如何将varchar类型的字段值转换为date类型?!在线等,急!!!!!!!!!!!!!!!
- 我定义一个每天凌晨4点中执行的任务,中间关闭数据库,于某一日的中午12点重新打开数据库,这个任务如何执行?
- 来看看如何写这条外连接的sql语句
- 问一个执行oracle的存储过程的问题
- 登录问题(各位请帮忙!!)
- oracle处理不了Long字段类型?
- 修改列属性,菜鸟求救
车辆5为车辆结束工作时间这两个你不认为字段三是不需要的吗?还是你在trigger中处理,将结束减开始就是车辆工作工作小时统计时按哪个?
)) from 表A where id='001' and 日期范围 between '2012-8-1'
and '2012-8-10'
create sequence a_squ;
create table a(
id int primary key,
cid int,
starttime date,
endtime date);insert into a values(a_squ.nextval,1,to_date('2012-03-04 08:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-04 10:05:04','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,1,to_date('2012-03-04 12:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-04 15:03:07','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,1,to_date('2012-03-05 12:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-05 18:03:04','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,2,to_date('2012-03-04 12:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-04 13:03:04','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,2,to_date('2012-03-05 12:03:05','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-05 17:03:04','yyyy-mm-dd hh24:mi:ss'));select
cid 车辆ID,
round(sum(endtime-starttime)*24) 车辆工作小时,
to_char(a.starttime,'yyyy-mm-dd') 日期
from a
where cid=1--id参数
and to_char(a.starttime,'yyyy-mm-dd') between '2012-03-01' and '2012-03-31'--两个日期参数
group by cid,to_char(a.starttime,'yyyy-mm-dd');
同行啊,程序员OR DBA?哪个公司的?select 车辆ID,trunc(开始工作时间),sum(工作小时)
from 表
where 开始工作时间 between 2012-8-1 到 2012-8-10
group by 车辆ID,trunc(开始工作时间)
select * from
(
select (trunc(sysdate,'mm')+level-1) as dt from dual
connect by rownum<=35
)
where trunc(sysdate,'mm')=trunc(dt,'mm');
create sequence a_squ;
create table a(
id int primary key,
cid int,
starttime date,
endtime date);
---插入数据
insert into a values(a_squ.nextval,1,to_date('2012-03-04 08:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-04 10:05:04','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,1,to_date('2012-03-04 12:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-04 15:03:07','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,1,to_date('2012-03-05 12:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-05 18:03:04','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,2,to_date('2012-03-04 12:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-04 13:03:04','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,2,to_date('2012-03-05 12:03:05','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-05 17:03:04','yyyy-mm-dd hh24:mi:ss'));---1、看结果有三个字段需要显示,车辆id直接呈现,日期,小时通过计算得到。--每天(每,各等关键字,使用group by),车辆工作小时=结束时间-开始时间
SELECT a.cid 车辆id,sum((a.endtime-a.starttime)*24) 车辆工作小时,--*24是因为带时分秒的日期计算结果单位是天,要得到小时就乘以24
trunc(a.starttime) 日期
FROM a
WHERE (这里填写日期统计的日期范围)
GROUP BY trunc(a.starttime),a.cid --trunc函数得到无时无分无秒的日期
--思路:自增主键,一般用到序列(如果主键不是显式插入,可以通过后台用触发器实现插入),这里就显式插入,创建序列,简单的默认序列。
create sequence a_squ;
create table a(
id int primary key,
cid int,
starttime date,
endtime date);
---插入数据
insert into a values(a_squ.nextval,1,to_date('2012-03-04 08:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-04 10:05:04','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,1,to_date('2012-03-04 12:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-04 15:03:07','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,1,to_date('2012-03-05 12:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-05 18:03:04','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,2,to_date('2012-03-04 12:03:04','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-04 13:03:04','yyyy-mm-dd hh24:mi:ss'));
insert into a values(a_squ.nextval,2,to_date('2012-03-05 12:03:05','yyyy-mm-dd hh24:mi:ss'),to_date('2012-03-05 17:03:04','yyyy-mm-dd hh24:mi:ss'));---1、看结果有三个字段需要显示,车辆id直接呈现,日期,小时通过计算得到。--每天(每,各等关键字,使用group by),车辆工作小时=结束时间-开始时间
SELECT a.cid 车辆id,sum((a.endtime-a.starttime)*24) 车辆工作小时,--*24是因为带时分秒的日期计算结果单位是天,要得到小时就乘以24
trunc(a.starttime) 日期
FROM a
WHERE (这里填写日期统计的日期范围)
GROUP BY trunc(a.starttime),a.cid --trunc函数得到无时无分无秒的日期