1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| SELECT ind.nom
,ind.prenom
,salaire.id
,salaire.prime
,salaire.dep
,sum(case when ("201201" >= DATE_FORMAT(debut, '%Y%m') and "201201" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/01/01")),GREATEST(debut,"2012/01/01")) +1)/(DATEDIFF(LAST_DAY("2012/01/01"),"2012/01/01")+1) else 0 end) as montant_01
,sum(case when ("201202" >= DATE_FORMAT(debut, '%Y%m') and "201202" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/02/01")),GREATEST(debut,"2012/02/01")) +1)/(DATEDIFF(LAST_DAY("2012/02/01"),"2012/02/01")+1) else 0 end) as montant_02
,sum(case when ("201203" >= DATE_FORMAT(debut, '%Y%m') and "201203" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/03/01")),GREATEST(debut,"2012/03/01")) +1)/(DATEDIFF(LAST_DAY("2012/03/01"),"2012/03/01")+1) else 0 end) as montant_03
,sum(case when ("201204" >= DATE_FORMAT(debut, '%Y%m') and "201204" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/04/01")),GREATEST(debut,"2012/04/01")) +1)/(DATEDIFF(LAST_DAY("2012/04/01"),"2012/04/01")+1) else 0 end) as montant_04
,sum(case when ("201205" >= DATE_FORMAT(debut, '%Y%m') and "201205" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/05/01")),GREATEST(debut,"2012/05/01")) +1)/(DATEDIFF(LAST_DAY("2012/05/01"),"2012/05/01")+1) else 0 end) as montant_05
,sum(case when ("201206" >= DATE_FORMAT(debut, '%Y%m') and "201206" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/06/01")),GREATEST(debut,"2012/06/01")) +1)/(DATEDIFF(LAST_DAY("2012/06/01"),"2012/06/01")+1) else 0 end) as montant_06
,sum(case when ("201207" >= DATE_FORMAT(debut, '%Y%m') and "201207" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/07/01")),GREATEST(debut,"2012/07/01")) +1)/(DATEDIFF(LAST_DAY("2012/07/01"),"2012/07/01")+1) else 0 end) as montant_07
,sum(case when ("201208" >= DATE_FORMAT(debut, '%Y%m') and "201208" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/08/01")),GREATEST(debut,"2012/08/01")) +1)/(DATEDIFF(LAST_DAY("2012/08/01"),"2012/08/01")+1) else 0 end) as montant_08
,sum(case when ("201209" >= DATE_FORMAT(debut, '%Y%m') and "201209" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/09/01")),GREATEST(debut,"2012/09/01")) +1)/(DATEDIFF(LAST_DAY("2012/09/01"),"2012/09/01")+1) else 0 end) as montant_09
,sum(case when ("201210" >= DATE_FORMAT(debut, '%Y%m') and "201210" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/10/01")),GREATEST(debut,"2012/10/01")) +1)/(DATEDIFF(LAST_DAY("2012/10/01"),"2012/10/01")+1) else 0 end) as montant_10
,sum(case when ("201211" >= DATE_FORMAT(debut, '%Y%m') and "201211" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/11/01")),GREATEST(debut,"2012/11/01")) +1)/(DATEDIFF(LAST_DAY("2012/11/01"),"2012/11/01")+1) else 0 end) as montant_11
,sum(case when ("201212" >= DATE_FORMAT(debut, '%Y%m') and "201212" <= DATE_FORMAT(fin, '%Y%m')) then montant*(DATEDIFF(LEAST(fin,LAST_DAY("2012/12/01")),GREATEST(debut,"2012/12/01")) +1)/(DATEDIFF(LAST_DAY("2012/12/01"),"2012/12/01")+1) else 0 end) as montant_12
FROM ind
INNER JOIN
salaire
ON ind.id = salaire.id
GROUP BY ind.nom
, ind.prenom
, salaire.id
, salaire.prime
,salaire.dep
ORDER BY nom,prenom,id,prime |
Partager