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
| --------------
START TRANSACTION
--------------
--------------
set session collation_connection = "latin1_general_ci"
--------------
--------------
DROP DATABASE IF EXISTS `base`
--------------
--------------
CREATE DATABASE IF NOT EXISTS `base`
DEFAULT CHARACTER SET `latin1`
DEFAULT COLLATE `latin1_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `test`
--------------
--------------
CREATE TABLE `test`
( `id` integer unsigned NOT NULL auto_increment primary key,
`date` date NOT NULL,
`categorie` varchar(255) NOT NULL,
`tps` decimal(10,2) NOT NULL,
`commentaire` varchar(255) NOT NULL,
`to` smallint unsigned NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `test` (`date`,`categorie`,`tps`,`commentaire`,`to`) VALUES
('2021-04-01','Depannage', 1.5, 'réparé moteur', 1),
('2021-04-03','Preventif', 2.0, 'remplacé contacteur', 1),
('2021-04-08','Astreinte', 2.0, 'réarmé thermostat', 2),
('2021-05-08','Graissage', 3.0, 'tapis et cvonvoyeurs', 2),
('2021-04-03','Automatisme', 4.0, 'modif chargement tapis', 1),
('2021-03-01','Depannage', 12.0, 'chaine entrainement', 2),
('2021-04-15','Preventif', 3.0, 'basculeur colis', 1),
('2021-03-02','Astreinte', 4.0, 'climatisation salle server', 1),
('2021-04-28','Graissage', 2.5, 'convoyeurs decharge', 2),
('2021-03-14','Automatisme', 2.0, 'chaufferie', 1),
('2021-04-30','Depannage', 6.0, 'éclairage hall', 1),
('2021-04-03','Preventif', 10.0, 'remplacé contacteur', 1),
('2021-03-01','Astreinte', 4.0, 'chauffage salle', 2),
('2021-04-30','Graissage', 20.0, 'parc véhicule', 1),
('2021-04-03','Automatisme', 15.0, 'tapis evacuation', 1),
('2021-03-01','Preventif', 6.0, 'fermeture automatique', 1)
--------------
--------------
select * from `test`
--------------
+----+------------+-------------+-------+----------------------------+----+
| id | date | categorie | tps | commentaire | to |
+----+------------+-------------+-------+----------------------------+----+
| 1 | 2021-04-01 | Depannage | 1.50 | réparé moteur | 1 |
| 2 | 2021-04-03 | Preventif | 2.00 | remplacé contacteur | 1 |
| 3 | 2021-04-08 | Astreinte | 2.00 | réarmé thermostat | 2 |
| 4 | 2021-05-08 | Graissage | 3.00 | tapis et cvonvoyeurs | 2 |
| 5 | 2021-04-03 | Automatisme | 4.00 | modif chargement tapis | 1 |
| 6 | 2021-03-01 | Depannage | 12.00 | chaine entrainement | 2 |
| 7 | 2021-04-15 | Preventif | 3.00 | basculeur colis | 1 |
| 8 | 2021-03-02 | Astreinte | 4.00 | climatisation salle server | 1 |
| 9 | 2021-04-28 | Graissage | 2.50 | convoyeurs decharge | 2 |
| 10 | 2021-03-14 | Automatisme | 2.00 | chaufferie | 1 |
| 11 | 2021-04-30 | Depannage | 6.00 | éclairage hall | 1 |
| 12 | 2021-04-03 | Preventif | 10.00 | remplacé contacteur | 1 |
| 13 | 2021-03-01 | Astreinte | 4.00 | chauffage salle | 2 |
| 14 | 2021-04-30 | Graissage | 20.00 | parc véhicule | 1 |
| 15 | 2021-04-03 | Automatisme | 15.00 | tapis evacuation | 1 |
| 16 | 2021-03-01 | Preventif | 6.00 | fermeture automatique | 1 |
+----+------------+-------------+-------+----------------------------+----+
--------------
SELECT *,
cast(100.0 * `tps` / SUM(`tps`) OVER() AS decimal(10,2)) AS PERCENT
FROM ( SELECT `categorie`,
SUM(`tps`) as tps
FROM `test`
WHERE `to`=1
GROUP BY `categorie`
ORDER BY `categorie`
) as x
--------------
+-------------+-------+---------+
| categorie | tps | PERCENT |
+-------------+-------+---------+
| Astreinte | 4.00 | 5.44 |
| Automatisme | 21.00 | 28.57 |
| Depannage | 7.50 | 10.20 |
| Graissage | 20.00 | 27.21 |
| Preventif | 21.00 | 28.57 |
+-------------+-------+---------+
--------------
COMMIT
--------------
Appuyez sur une touche pour continuer... |