update zhibiaoku set 部门=(select 部门 from denglu where denglu.`姓名`=zhibiaoku.`姓名`);
truncate yuebao;
insert into yuebao(成员,月完成) select 部门 as 成员,sum(移网) from fazhanku where substring(日期,5,2)="04" group by 部门;
update yuebao set 月指标=(select sum(zhibiaoku.移网) from zhibiaoku where zhibiaoku.部门=yuebao.成员);
update yuebao set 月完成率=月完成/`月指标`;
select DATEDIFF(date_add(curdate()-day(curdate())+1 ,interval 1 month ) ,DATE_ADD(curdate(),interval -day(curdate())+1 day)) into @daysa from dual;
select day(now()) into @days;
update yuebao set 序时指标=ceil(@days/@daysa*月指标) ;
update yuebao set 序时完成=月完成;
update yuebao set 序时完成率=序时完成/`序时指标`;
update yuebao set `日指标` =(select 指标 from (select AA.成员 as 成员,CEIL((AA.`月指标`-BB.移网)/(@daysa-@days+1)) as 指标 from (select 成员,月指标 from yuebao GROUP BY 成员) as AA,(select 部门,sum(移网) as 移网 from fazhanku where substring(日期,5,2)="04" and CONVERT(RIGHT(日期,2),SIGNED)<=@days-1 group by 部门) as BB where AA.成员=BB.部门) as CC where yuebao.`成员`=CC.成员);
update yuebao set 日完成=( select sum(移网) from fazhanku where right(日期,2)=@days and fazhanku.`部门`=yuebao.`成员` group by 部门);
update yuebao set `日完成率`=`日完成`/`日指标`;
update yuebao set `明日指标` =(select 指标 from (select AA.成员 as 成员,CEIL((AA.`月指标`-BB.移网)/(@daysa-@days)) as 指标 from (select 成员,月指标 from yuebao GROUP BY 成员) as AA,(select 部门,sum(移网) as 移网 from fazhanku where substring(日期,5,2)="04" group by 部门) as BB where AA.成员=BB.部门) as CC where yuebao.`成员`=CC.成员);
update yuebao set 日完成=0 , `日完成率`=0 ,日指标=0,明日指标=0 where 日完成 is null or `日完成率` is NULL or 日指标<0 or 明日指标<0;
select * from yuebao;
|