create table xxaso as select cia, empleado, ahorro, aporte, 0 ahoemp, 0 proemp from asomaestro@asell where estado='A'; update xxaso x set ahoemp=(select sum(monto) from plaestadisticas e where e.cia=x.cia and e.empleado=x.empleado and e.origen='D' and tipomov in ('102','112')); update xxaso x set proemp=(select sum(monto) from plaestadisticas e where e.cia=x.cia and e.empleado=x.empleado and e.origen='P' and tipomov in ('102','112')); select cia, empleado, count(*) from plaestadisticas where tipomov in ('102','112') and origen in ('D','P') group by cia, empleado having count(*)>2; select empleado, ahorro, aporte, ahoemp, proemp from xxaso where ahorro!=ahoemp or aporte!=proemp; select sum(ahorro-ahoemp) ahorro, sum(aporte-proemp) aporte from xxaso where ahorro!=ahoemp or aporte!=proemp; create table plaestadisticasbak as select * from plaestadisticas; delete plaestadisticas where cia='001' and tipomov in ('102','112') and origen in ('D','P'); insert into plaestadisticas (CIA, EMPLEADO, TIPOMOV, ORIGEN, MONTO) select cia, empleado, '102','D', ahorro from xxaso where cia='001'; insert into plaestadisticas (CIA, EMPLEADO, TIPOMOV, ORIGEN, MONTO) select cia, empleado, '102','P', aporte from xxaso where cia='001'; update plaestadisticas e set monto=(select monto/10 from plaestadisticas x where x.cia=e.cia and x.empleado=e.empleado and x.tipomov='109') where cia='001' and tipomov='127' and origen='P'; delete plaestadisticas e where cia='001' and tipomov='127' and not exists (select 1 from plaestadisticas x where x.cia=e.cia and x.empleado=e.empleado and x.tipomov='109'); select tipomov, count(*) from plaestadisticas where cia='001' group by tipomov; Monto mensual vs monto periodo ?