Bonjour,

J'ai crée une procédure stockée qui me permet de sortir des statistiques de fréquentation pour des logements mais entre la requête executée directement dans mysql workbench et la procédure stockée que j'ai crée certaines sommes sont doublées :
Appel de la procédure
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
call location_generer_statistiques_saison('2011-04-09','2011-11-26','ETE 2011')
Code de la procédure
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
29
30
31
32
33
 
DELIMITER $$
 
CREATE DEFINER=`root`@`localhost` PROCEDURE `location_generer_statistiques_saison`(date_debut CHAR(10),date_fin CHAR(10),saison CHAR(10))
BEGIN
SELECT id_evenement, logement, 
SUM(total_demandes_enregistrees) AS total_demandes_enregistrees, 
SUM(total_demandes_attribuees) AS total_demandes_attribuees, 
SUM(total_journees_attribuees) AS total_journees_attribuees, 
SUM(total_semaines_attribuees) AS total_semaines_attribuees,  
SUM(total_journees) AS total_journees, 
SUM(total_semaines) AS total_semaines, 
SUM(total_journees) - SUM(total_journees_attribuees) AS total_journees_difference, 
SUM(total_semaines) - SUM(total_semaines_attribuees) AS total_semaines_difference, 
IF(ROUND(100 - ((SUM(total_journees) - SUM(total_journees_attribuees)) / SUM(total_journees) * 100)) IS NULL ,0,ROUND(100 - ((SUM(total_journees) - SUM(total_journees_attribuees)) / SUM(total_journees) * 100))) AS ratio_remplissage 
FROM (
 select `d`.`id_evenement` AS `id_evenement`,replace(`e`.`libelle`,'- NUITEE','') AS `logement`, 0 AS `total_demandes_enregistrees`,if(isnull(sum(`d`.`demandes`)),0,sum(`d`.`demandes`)) AS `total_demandes_attribuees`,sum(if((`d`.`journees` = 8),(`d`.`journees` - 1),`d`.`journees`)) AS `total_journees_attribuees`,truncate((sum(if((`d`.`journees` = 8),(`d`.`journees` - 1),`d`.`journees`)) / 7),0) AS `total_semaines_attribuees`,0 AS `total_journees`,0 AS `total_semaines` 
 from (`location_demandes_synthese` `d` left join `evenement` `e` on((`e`.`id_evenement` = `d`.`id_evenement`))) 
 where ((`d`.`date_debut` between date_debut and date_fin) and (`d`.`id_evenement_demande_statut` in (1,11)) and (`d`.`date_debut` < date_fin)) 
 group by replace(`e`.`libelle`,'- NUITEE','') 
union all 
 select `id_evenement` AS `id_evenement`,replace(`libelle`,'- NUITEE','') AS `logement`, 0 AS `total_demandes_enregistrees`,0 AS `total_demandes_attribuees`,0 AS `total_journees_attribuees`,0 AS `total_semaines_attribuees`,sum(`duree`) AS `total_journees`, truncate((sum(`duree`) / 7),0) AS `total_semaines` 
 from `location_periodes_synthese` 
 where ((`saison` = saison) and (((`id_evenement_type` = 2) and (`saison` is not null)) or (`id_evenement_type` = 4))) 
 group by replace(`libelle`,'- NUITEE','') 
union all 
 select `d`.`id_evenement` AS `id_evenement`,replace(`e`.`libelle`,'- NUITEE','') AS `logement`, if(isnull(sum(`d`.`demandes`)),0,sum(`d`.`demandes`)) AS `total_demandes_enregistrees`, 0 AS `total_demandes_attribuees`, 0 AS `total_journees_attribuees`, 0 AS `total_semaines_attribuees`, 0 AS `total_journees`,0 AS `total_semaines` 
 from (`location_demandes_synthese` `d` left join `evenement` `e` on((`e`.`id_evenement` = `d`.`id_evenement`))) 
 where ((`d`.`date_debut` between date_debut and date_fin) and (`d`.`date_debut` < date_fin)) 
 group by replace(`e`.`libelle`,'- NUITEE','')) 
travail 
GROUP BY logement;
END
Résultat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
29
+--------------+------------------------------+-----------------------------+---------------------------+---------------------------+---------------------------+----------------+----------------+---------------------------+---------------------------+-------------------+
| id_evenement | logement                     | total_demandes_enregistrees | total_demandes_attribuees | total_journees_attribuees | total_semaines_attribuees | total_journees | total_semaines | total_journees_difference | total_semaines_difference | ratio_remplissage |
+--------------+------------------------------+-----------------------------+---------------------------+---------------------------+---------------------------+----------------+----------------+---------------------------+---------------------------+-------------------+
|           41 | BEDOUS - 4 PLACES - 1        |                          20 |                         8 |                        40 |                         5 |            364 |             52 |                       324 |                        47 |                11 |
|           42 | BEDOUS - 4 PLACES - 2        |                           5 |                         4 |                        28 |                         4 |            364 |             52 |                       336 |                        48 |                 8 |
|           43 | BEDOUS - 4 PLACES - 3        |                           4 |                         4 |                        25 |                         3 |            364 |             52 |                       339 |                        49 |                 7 |
|           44 | BEDOUS - 4 PLACES - 4        |                           5 |                         5 |                        24 |                         3 |            364 |             52 |                       340 |                        49 |                 7 |
|           53 | BEDOUS - 4 PLACES - 5        |                          10 |                        10 |                        66 |                         9 |            364 |             52 |                       298 |                        43 |                18 |
|           54 | BEDOUS - 4 PLACES - 6        |                           6 |                         6 |                        42 |                         6 |            364 |             52 |                       322 |                        46 |                12 |
|          100 | BIDART - 6 PLACES            |                          44 |                        25 |                        21 |                         3 |             70 |             10 |                        49 |                         7 |                30 |
|           40 | BIELLE - 10 LITS             |                          13 |                        11 |                        33 |                         4 |            728 |            104 |                       695 |                       100 |                 5 |
|           37 | BIELLE - 4 LITS              |                           8 |                         8 |                        33 |                         4 |            728 |            104 |                       695 |                       100 |                 5 |
|           38 | BIELLE - 6 LITS - 1          |                           9 |                         9 |                        31 |                         4 |            728 |            104 |                       697 |                       100 |                 4 |
|           92 | BIELLE - 6 LITS - 2          |                           1 |                         1 |                         3 |                         0 |            728 |            104 |                       725 |                       104 |                 0 |
|          101 | CAPBRETON - 4 PLACES         |                          42 |                        24 |                        63 |                         9 |            119 |             17 |                        56 |                         8 |                53 |
|           48 | CAUTERETS - 8 PLACES         |                          22 |                        15 |                       105 |                        15 |            294 |             42 |                       189 |                        27 |                36 |
|          103 | CHANIERS - 4 PLACES          |                           3 |                         3 |                        13 |                         1 |            182 |             26 |                       169 |                        25 |                 7 |
|          104 | CHANIERS - 6 PLACES - 1      |                           3 |                         3 |                        12 |                         1 |            182 |             26 |                       170 |                        25 |                 7 |
|          105 | CHANIERS - 6 PLACES - 2      |                           0 |                         0 |                         0 |                         0 |            182 |             26 |                       182 |                        26 |                 0 |
|           46 | LA TREMBLADE PN - 4 PLACES   |                          19 |                        14 |                        86 |                        12 |            546 |             78 |                       460 |                        66 |                16 |
|           47 | LA TREMBLADE PN - 6 PLACES   |                          26 |                        18 |                       111 |                        15 |            546 |             78 |                       435 |                        63 |                20 |
|          102 | LEON - 6 PLACES              |                          68 |                        42 |                        80 |                        11 |            175 |             25 |                        95 |                        14 |                46 |
|           45 | LES EYZIES - 6 PLACES        |                          23 |                        19 |                       124 |                        17 |            546 |             78 |                       422 |                        61 |                23 |
|           98 | LOIX EN RE - 6 PLACES        |                          48 |                        19 |                        42 |                         6 |             84 |             12 |                        42 |                         6 |                50 |
|           49 | LUZ SAINT SAUVEUR - 4 PLACES |                           0 |                         0 |                         0 |                         0 |             56 |              8 |                        56 |                         8 |                 0 |
|           51 | PEYRAGUDES - 6 PLACES        |                           0 |                         0 |                         0 |                         0 |             84 |             12 |                        84 |                        12 |                 0 |
|           99 | SABLES D'OLONNE - 4 PLACES   |                          31 |                        14 |                        49 |                         7 |            168 |             24 |                       119 |                        17 |                29 |
|           50 | SAINT LARY - 6 PLACES        |                          24 |                        15 |                        95 |                        13 |            364 |             52 |                       269 |                        39 |                26 |
+--------------+------------------------------+-----------------------------+---------------------------+---------------------------+---------------------------+----------------+----------------+---------------------------+---------------------------+-------------------+
Mon nombre de journées est doublé alors que si je reprend les requêtes de la procédure en remplaçant donc mes variables par leurs valeurs j'obtiens les bons résultats, c'est à dire pile la moitié du nombre de jours total (dont découle nombre de semaines total) faussant mon ratio de remplissage.

Une idée ?

Merci