存储过程 查询出多条数据批量插入表 增加出库通知单统计按机构分组事件
Posted tonggc1668
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了存储过程 查询出多条数据批量插入表 增加出库通知单统计按机构分组事件相关的知识,希望对你有一定的参考价值。
use wms;
drop table if exists riv_outbound_notice_statistics_groupby_org;
-- 增加出库通知单统计按机构分组表
CREATE TABLE `riv_outbound_notice_statistics_groupby_org` (
`ONSGO_ID` int(10) NOT NULL AUTO_INCREMENT COMMENT ‘主键ID‘,
`BEGIN_TIME` datetime NOT NULL COMMENT ‘统计起始时间‘,
`END_TIME` datetime NOT NULL COMMENT ‘统计结束时间‘,
`ONH_TOTAL_QTY` bigint(19) NOT NULL DEFAULT ‘0‘ COMMENT ‘出库通知单总创建量‘,
`ONH_SHIPED_QTY` bigint(19) NOT NULL DEFAULT ‘0‘ COMMENT ‘出库通知单已发货量‘,
`ORG_ID` int(10) NOT NULL COMMENT ‘机构ID‘,
`ORG_CODE` varchar(40) NOT NULL COMMENT ‘机构代码‘,
`ORG_NAME` varchar(100) NOT NULL COMMENT ‘机构名称‘,
PRIMARY KEY (`ONSGO_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=‘出库通知单统计按机构分组表‘;
drop procedure if exists pro_outbound_notice_statistics_groupby_org;
-- 增加出库通知单统计按机构分组函数
delimiter //
create procedure `pro_outbound_notice_statistics_groupby_org`()
begin
DECLARE curtime VARCHAR(50);
DECLARE pretime VARCHAR(50);
set curtime = CONCAT(DATE_FORMAT(now(),‘%Y-%m-%d ‘),‘00:00:00‘);
set pretime = date_sub(curtime, interval 1 day);
insert into riv_outbound_notice_statistics_groupby_org(`BEGIN_TIME`, `END_TIME`,`ONH_TOTAL_QTY`, `ONH_SHIPED_QTY`,`ORG_ID`,`ORG_CODE`, `ORG_NAME`)
select
pretime,
curtime,
tab.totalQty,
tab2.shipedQty,
tab.orgId,
org.ORG_CODE,
org.ORG_NAME
FROM
(
SELECT
count(1) AS totalQty,
ONH_ORG_ID AS orgId
FROM
riv_outbound_notice_h onh
WHERE
onh.CREATE_TIME < curtime
AND onh.CREATE_TIME >= pretime
GROUP BY
onh.ONH_ORG_ID
) tab
LEFT JOIN (
SELECT
count(1) AS shipedQty,
ONH_ORG_ID AS orgId
FROM
riv_outbound_notice_h onh
WHERE
onh.ONH_STATUS = 90
AND onh.ONH_SHIP_DATETIME < curtime
AND onh.ONH_SHIP_DATETIME >= pretime
GROUP BY
onh.ONH_ORG_ID
) tab2 ON tab.orgId = tab2.orgId
INNER JOIN riv_organization org ON tab.orgId = org.ORG_ID;
end//
delimiter ;
drop event if exists event_auto_outbound_notice_statistics_groupby_org;
set global event_scheduler=‘on‘;
-- 增加出库通知单统计按机构分组事件
CREATE EVENT `event_auto_outbound_notice_statistics_groupby_org`
ON SCHEDULE EVERY 1 DAY STARTS ‘2017-11-10 00:00:00‘ ENDS ‘2018-01-01 00:00:00‘
ON COMPLETION NOT PRESERVE
ENABLE
DO
CALL pro_outbound_notice_statistics_groupby_org();
以上是关于存储过程 查询出多条数据批量插入表 增加出库通知单统计按机构分组事件的主要内容,如果未能解决你的问题,请参考以下文章