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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
-- --------------------------------------------------------
--
-- Structure de la table `2017resultats`
--
--
-- Structure de la table `2017resultats`
--
DROP TABLE IF EXISTS `2017resultats`;
CREATE TABLE `2017resultats` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sport` Varchar(10) NOT NULL DEFAULT '0',
`mois` int(2) NOT NULL DEFAULT '0',
`somme` int(6) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Contenu de la table `2017resultats`
--
SET @annee = 2017;
SET @V1 := (SELECT SUM(distance_parcours) FROM parcours as p
INNER JOIN sorties AS s
ON p.id_parcours = s.parcours_id_parcours
WHERE YEAR(s.date_sorties) = @annee AND MONTH(s.date_sorties) = 01 AND p.sport_parcours = 'V');
DROP PROCEDURE IF EXISTS `sommes_mensuelles`;
DELIMITER |
CREATE PROCEDURE sommes_mensuelles (IN _sport VARCHAR(4), IN _mois INT, IN _an INT, OUT res INT)
LANGUAGE SQL
BEGIN
SET @query = (SELECT CONCAT(
'SELECT SUM(distance_parcours) FROM parcours as p
INNER JOIN sorties AS s
ON p.id_parcours = s.parcours_id_parcours
WHERE YEAR(s.date_sorties) = ''',
_an,
''' AND MONTH(s.date_sorties) = ''',
_mois,
''' AND p.sport_parcours = ''',
_sport,
'' ));
PREPARE stmt FROM @query ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;
END;
|
DELIMITER ;
CALL sommes_mensuelles ('V', 04, @annee, @V2);
SELECT @V2;
INSERT INTO `2017resultats` (`sport`, `mois`, `somme`) VALUES
('V', 1, @V1),
('V', 2, @V2),
('V', 3, 0),
('V', 4, 0),
('V', 5, 0),
('V', 6, 0),
('V', 7, 0),
('V', 8, 0),
('V', 9, 0),
('V', 10, 0),
('V', 11, 0),
('V', 12, 0),
('V', 13, 0),
('C', 1, 0),
('C', 2, 0),
('C', 3, 0),
('C', 4, 0),
('C', 5, 0),
('C', 6, 0),
('C', 7, 0),
('C', 8, 0),
('C', 9, 0),
('C', 10, 0),
('C', 11, 0),
('C', 12, 0),
('C', 13, 0),
('N', 1, 0),
('N', 2, 0),
('N', 3, 0),
('N', 4, 0),
('N', 5, 0),
('N', 6, 0),
('N', 7, 0),
('N', 8, 0),
('N', 9, 0),
('N', 10, 0),
('N', 11, 0),
('N', 12, 0),
('N', 13, 0);
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
Partager