ALTER TABLE hcollege ADD COLUMN codeBaseTarification VARCHAR(50);

UPDATE hcollege h
JOIN college c ON ((c.id=h.idCollege) AND (c.idPolice=h.idPolice))
SET h.codeBaseTarification=c.codeBaseTarification ; 
 
 
 DROP TABLE hprimecollege; 
 
 CREATE TABLE hprimecollege (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `exercice` VARCHAR(4) DEFAULT NULL,
  `userSave` VARCHAR(50) DEFAULT NULL,
  `codeSociete` VARCHAR(50) DEFAULT NULL,
  `idCollege` INT(11) DEFAULT '0',
  `idPolice` INT(11) DEFAULT '0',
  `codeLienParente` VARCHAR(50) DEFAULT '',
  `population` INT(11) DEFAULT '0',
  `prime` DECIMAL(10,0) DEFAULT '0',
  `primeMin` DECIMAL(10,0) DEFAULT '0',
  `primeMax` DECIMAL(10,0) DEFAULT '0',
  `dateSysteme` DATETIME,
  `dateSave` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `codeUtilisateur` VARCHAR(50) DEFAULT '',
  `forfait` CHAR(1) DEFAULT '1',
  `forfaitPlafond` DECIMAL(10,0) DEFAULT '0',
  `plafondBeneficiaire` DECIMAL(10,0) DEFAULT '0',
  `tauxPlafond` DECIMAL(10,2) DEFAULT '0.00',
  PRIMARY KEY (`id`),
  UNIQUE KEY `codeSociete` (`codeSociete`,`idCollege`,`idPolice`,`codeLienParente`,`exercice`,`prime`)
) ENGINE=MYISAM AUTO_INCREMENT=10167 DEFAULT CHARSET=utf8;


INSERT INTO hprimecollege (exercice,userSave,codeSociete,
idCollege,idPolice,codeLienParente,population,prime,primeMin,primeMax,
dateSysteme,codeUtilisateur,forfait,forfaitPlafond,plafondBeneficiaire,tauxPlafond)

SELECT
DISTINCT p.exercice,'lionel' userSave,c.codeSociete,
c.idCollege,c.idPolice,c.codeLienParente,c.population,c.prime,c.primeMin,c.primeMax,
c.dateSysteme,c.codeUtilisateur,c.forfait,c.forfaitPlafond,c.plafondBeneficiaire,c.tauxPlafond
FROM  primecollege c
JOIN hpolice p ON (p.idPolice=c.idPolice) ;

-- vitalis-267-184-A-2022

SELECT c.* FROM  hprimecollege c WHERE idPolice=184 AND idCollege=267
SELECT * FROM hpolice  WHERE idPolice=184 AND  numeroAvenant=0;-- and c.idCollege=269;