delete from ccmanager where pid=702;

delete from centers where pid=702;
delete from centers_groups where pid=702;

delete from categs where pid=702;
delete from categs_groups where pid=702;

insert into centers_groups (pid,code_center_group,desc_center_group)
select 702,code_center_group,desc_center_group
from centers_groups
where pid = 701;

insert ignore into centers (pid,code_center_group,code_center,desc_center,comm_center)
select 702,code_center_group,code_center,desc_center,comm_center
from centers
where pid = 701;

INSERT INTO `categs_groups` (`pid`, `code_categ_group`, `desc_categ_group`) VALUES
(702,	'00',	'Population Group');

INSERT INTO `categs` (`pid`, `code_categ`, `desc_categ`, `um`, `comm_categ`, `code_categ_group`, `isgroup`) VALUES
(702,	'01',	'Population',	'--',	NULL,	'00',	'GRP0');

truncate table ain_pop;

/* 1950 */

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1950,'00',yr1950*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1950,'00',yr1950*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1951,'00',(yr1951-yr1950)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1951,'00',(yr1951-yr1950)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1952,'00',(yr1952-yr1951)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1952,'00',(yr1952-yr1951)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1953,'00',(yr1953-yr1952)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1953,'00',(yr1953-yr1952)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1954,'00',(yr1954-yr1953)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1954,'00',(yr1954-yr1953)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1955,'00',(yr1955-yr1954)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1955,'00',(yr1955-yr1954)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1956,'00',(yr1956-yr1955)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1956,'00',(yr1956-yr1955)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1957,'00',(yr1957-yr1956)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1957,'00',(yr1957-yr1956)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1958,'00',(yr1958-yr1957)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1958,'00',(yr1958-yr1957)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1959,'00',(yr1959-yr1958)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1959,'00',(yr1959-yr1958)*1000
from ain_pop_female x;

/* 1960 */
insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1960,'00',(yr1960-yr1959)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1960,'00',(yr1960-yr1959)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1961,'00',(yr1961-yr1960)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1961,'00',(yr1961-yr1960)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1962,'00',(yr1962-yr1961)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1962,'00',(yr1962-yr1961)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1963,'00',(yr1963-yr1962)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1963,'00',(yr1963-yr1962)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1964,'00',(yr1964-yr1963)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1964,'00',(yr1964-yr1963)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1965,'00',(yr1965-yr1964)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1965,'00',(yr1965-yr1964)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1966,'00',(yr1966-yr1965)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1966,'00',(yr1966-yr1965)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1967,'00',(yr1967-yr1966)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1967,'00',(yr1967-yr1966)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1968,'00',(yr1968-yr1967)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1968,'00',(yr1968-yr1967)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1969,'00',(yr1969-yr1968)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1969,'00',(yr1969-yr1968)*1000
from ain_pop_female x;


/* 1970 */
insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1970,'00',(yr1970-yr1969)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1970,'00',(yr1970-yr1969)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1971,'00',(yr1971-yr1970)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1971,'00',(yr1971-yr1970)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1972,'00',(yr1972-yr1971)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1972,'00',(yr1972-yr1971)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1973,'00',(yr1973-yr1972)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1973,'00',(yr1973-yr1972)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1974,'00',(yr1974-yr1973)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1974,'00',(yr1974-yr1973)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1975,'00',(yr1975-yr1974)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1975,'00',(yr1975-yr1974)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1976,'00',(yr1976-yr1975)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1976,'00',(yr1976-yr1975)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1977,'00',(yr1977-yr1976)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1977,'00',(yr1977-yr1976)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1978,'00',(yr1978-yr1977)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1978,'00',(yr1978-yr1977)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1979,'00',(yr1979-yr1978)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1979,'00',(yr1979-yr1978)*1000
from ain_pop_female x;

/* 1980 */
insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1980,'00',(yr1980-yr1979)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1980,'00',(yr1980-yr1979)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1981,'00',(yr1981-yr1980)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1981,'00',(yr1981-yr1980)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1982,'00',(yr1982-yr1981)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1982,'00',(yr1982-yr1981)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1983,'00',(yr1983-yr1982)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1983,'00',(yr1983-yr1982)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1984,'00',(yr1984-yr1983)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1984,'00',(yr1984-yr1983)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1985,'00',(yr1985-yr1984)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1985,'00',(yr1985-yr1984)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1986,'00',(yr1986-yr1985)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1986,'00',(yr1986-yr1985)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1987,'00',(yr1987-yr1986)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1987,'00',(yr1987-yr1986)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1988,'00',(yr1988-yr1987)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1988,'00',(yr1988-yr1987)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1989,'00',(yr1989-yr1988)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1989,'00',(yr1989-yr1988)*1000
from ain_pop_female x;

/* 1990 */
insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1990,'00',(yr1990-yr1989)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1990,'00',(yr1990-yr1989)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1991,'00',(yr1991-yr1990)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1991,'00',(yr1991-yr1990)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1992,'00',(yr1992-yr1991)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1992,'00',(yr1992-yr1991)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1993,'00',(yr1993-yr1992)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1993,'00',(yr1993-yr1992)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1994,'00',(yr1994-yr1993)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1994,'00',(yr1994-yr1993)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1995,'00',(yr1995-yr1994)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1995,'00',(yr1995-yr1994)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1996,'00',(yr1996-yr1995)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1996,'00',(yr1996-yr1995)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1997,'00',(yr1997-yr1996)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1997,'00',(yr1997-yr1996)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1998,'00',(yr1998-yr1997)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1998,'00',(yr1998-yr1997)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',1999,'00',(yr1999-yr1998)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',1999,'00',(yr1999-yr1998)*1000
from ain_pop_female x;

/* 2000 */

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2000,'00',(yr2000-yr1999)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2000,'00',(yr2000-yr1999)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2001,'00',(yr2001-yr2000)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2001,'00',(yr2001-yr2000)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2002,'00',(yr2002-yr2001)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2002,'00',(yr2002-yr2001)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2003,'00',(yr2003-yr2002)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2003,'00',(yr2003-yr2002)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2004,'00',(yr2004-yr2003)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2004,'00',(yr2004-yr2003)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2005,'00',(yr2005-yr2004)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2005,'00',(yr2005-yr2004)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2006,'00',(yr2006-yr2005)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2006,'00',(yr2006-yr2005)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2007,'00',(yr2007-yr2006)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2007,'00',(yr2007-yr2006)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2008,'00',(yr2008-yr2007)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2008,'00',(yr2008-yr2007)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2009,'00',(yr2009-yr2008)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2009,'00',(yr2009-yr2008)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2010,'00',(yr2010-yr2009)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2010,'00',(yr2010-yr2009)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2011,'00',(yr2011-yr2010)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2011,'00',(yr2011-yr2010)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2012,'00',(yr2012-yr2011)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2012,'00',(yr2012-yr2011)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2013,'00',(yr2013-yr2012)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2013,'00',(yr2013-yr2012)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2014,'00',(yr2014-yr2013)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2014,'00',(yr2014-yr2013)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2015,'00',(yr2015-yr2014)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2015,'00',(yr2015-yr2014)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2016,'00',(yr2016-yr2015)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2016,'00',(yr2016-yr2015)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2017,'00',(yr2017-yr2016)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2017,'00',(yr2017-yr2016)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2018,'00',(yr2018-yr2017)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2018,'00',(yr2018-yr2017)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2019,'00',(yr2019-yr2018)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2019,'00',(yr2019-yr2018)*1000
from ain_pop_female x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 1,'',region,'01',2020,'00',(yr2020-yr2019)*1000
from ain_pop_male x;

insert into ain_pop (mid,code_center,region,code_categ,year,age,total)
select 2,'',region,'01',2020,'00',(yr2020-yr2019)*1000
from ain_pop_female x;

update ain_pop a set a.code_center = (select x.code_center from centers x where x.desc_center = a.region and x.pid = 702); 

update ain_pop a set a.code_center = 'IRN' where region = 'Iran (Islamic Republic of)';
update ain_pop a set a.code_center = 'RUS' where region = 'Russian Federation';



delete from ain_pop where code_center is null;


insert ignore into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select code_center,code_categ,concat(year,'-12-31'),total,total,mid,702
from ain_pop;

insert ignore into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select code_center,code_categ,concat(year,'-12-31'),sum(total),sum(total),3,702
from ain_pop
group by code_center,code_categ,year;