oracle 查询语句合并优化,高手们看看

[复制链接]
查看11 | 回复1 | 2010-11-12 12:36:30 | 显示全部楼层 |阅读模式
insert into RP_NE_ERR_TOTAL (RECEIVE_DATE,NE_DEVICE_ID,NE_DEVICE_NAME,NE_DEVICE_NAME)
select trunc(sysdate),nd.device_id,nd.name,count(1) from wo_ne_order wno,ne_device nd
where nd.device_id = wno.device_id
and wno.state_code in ('10E','10A','10W','10R','10RE','10M','10N')
and wno.create_date > trunc(sysdate)
and wno.finish_date > trunc(sysdate)
group by nd.device_id,nd.name;
insert into RP_NE_ERR_TOTAL (ERR_FINISH_CNT)
select count(1) from wo_ne_order wno,ne_device nd
where nd.device_id = wno.device_id
and wno.state_code in ('10M','10N')
and wno.finish_date > trunc(sysdate)
group by nd.device_id,nd.name;
insert into RP_NE_ERR_TOTAL (TWO_DATE_CNT)
select trunc(sysdate),nd.device_id,nd.name,count(1) from wo_ne_order wno,ne_device nd
where nd.device_id = wno.device_id
and wno.state_code in ('10M','10N')
and wno.create_date > trunc(sysdate -1)
and wno.create_datetrunc(sysdate)
group by nd.device_id,nd.name;
insert into RP_NE_ERR_TOTAL (THR_DATE_CNT)
select trunc(sysdate),nd.device_id,nd.name,count(1) from wo_ne_order wno,ne_device nd
where nd.device_id = wno.device_id
and wno.state_code in ('10M','10N')
and wno.create_date > trunc(sysdate-2)
and wno.create_datetrunc(sysdate)
group by nd.device_id,nd.name;

insert into RP_NE_ERR_TOTAL (ATH_DATE_CNT)
select trunc(sysdate),nd.device_id,nd.name,count(1) from wo_ne_order wno,ne_device nd
where nd.device_id = wno.device_id
and wno.state_code in ('10M','10N')
and wno.create_datetrunc(sysdate)
group by nd.device_id,nd.name;

insert into RP_NE_ERR_TOTAL (ERR_LEAVE_CNT)
select count(1) from wo_ne_order wno
where wno.state_code in ('10E','10A','10W','10R','10RE');
有高手能否将上述几个查询语句合并一下,我觉得这样效率有点点低。比如使用decode或者case when或者还有其他什么好方法。

回复

使用道具 举报

千问 | 2010-11-12 12:36:30 | 显示全部楼层
用视图CREATE VIEW V_TEMP AS select 1 A,1 B,1 C from dual;insert into temp select * from V_TEMP;就像这样CREATE VIEW V_TEMP1 ASselect trunc(sysdate),nd.device_id,nd.name,count(1) from wo_ne_order wno,ne_device ndwhere nd.device_id = wno.device_idand wno.state_code in ('10E','10A','10W','10R','10RE','10M','10N')and wno
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行