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 116 117
| --------------
SET AUTOCOMMIT = 0
--------------
--------------
START TRANSACTION
--------------
--------------
DROP DATABASE IF EXISTS `base`
--------------
--------------
CREATE DATABASE `base`
DEFAULT CHARACTER SET `latin1`
DEFAULT COLLATE `latin1_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `calendrier`
--------------
--------------
CREATE TABLE `calendrier`
( `matricule` integer unsigned NOT NULL,
`date` date NOT NULL,
`starttime` time NOT NULL,
`endtime` time NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
insert into `calendrier` (`matricule`,`date`,`starttime`,`endtime`) values
(12, '2017-05-28', '08:00:00', '17:10:00'),
(25, '2017-05-28', '08:15:00', '16:45:00'),
(12, '2017-05-29', '08:10:00', '17:00:00'),
(25, '2017-05-29', '08:15:00', '17:10:00'),
(12, '2017-05-30', '08:05:00', '17:05:00'),
(25, '2017-05-30', '08:20:00', '17:35:00'),
(12, '2017-05-31', '08:00:00', '17:05:00'),
(25, '2017-05-31', '07:45:00', '17:15:00'),
(12, '2017-06-01', '08:15:00', '16:45:00'),
(25, '2017-06-01', '08:00:00', '17:05:00'),
(12, '2017-06-02', '08:10:00', '18:00:00'),
(25, '2017-06-02', '07:40:00', '17:05:00'),
(12, '2017-06-03', '08:00:00', '17:10:00'),
(25, '2017-06-03', '08:05:00', '17:00:00'),
(12, '2017-06-04', '08:05:00', '17:20:00'),
(25, '2017-06-04', '08:10:00', '17:15:00'),
(12, '2017-06-05', '08:00:00', '17:10:00'),
(25, '2017-06-05', '08:20:00', '17:05:00')
--------------
--------------
select * from `calendrier`
--------------
+-----------+------------+-----------+----------+
| matricule | date | starttime | endtime |
+-----------+------------+-----------+----------+
| 12 | 2017-05-28 | 08:00:00 | 17:10:00 |
| 25 | 2017-05-28 | 08:15:00 | 16:45:00 |
| 12 | 2017-05-29 | 08:10:00 | 17:00:00 |
| 25 | 2017-05-29 | 08:15:00 | 17:10:00 |
| 12 | 2017-05-30 | 08:05:00 | 17:05:00 |
| 25 | 2017-05-30 | 08:20:00 | 17:35:00 |
| 12 | 2017-05-31 | 08:00:00 | 17:05:00 |
| 25 | 2017-05-31 | 07:45:00 | 17:15:00 |
| 12 | 2017-06-01 | 08:15:00 | 16:45:00 |
| 25 | 2017-06-01 | 08:00:00 | 17:05:00 |
| 12 | 2017-06-02 | 08:10:00 | 18:00:00 |
| 25 | 2017-06-02 | 07:40:00 | 17:05:00 |
| 12 | 2017-06-03 | 08:00:00 | 17:10:00 |
| 25 | 2017-06-03 | 08:05:00 | 17:00:00 |
| 12 | 2017-06-04 | 08:05:00 | 17:20:00 |
| 25 | 2017-06-04 | 08:10:00 | 17:15:00 |
| 12 | 2017-06-05 | 08:00:00 | 17:10:00 |
| 25 | 2017-06-05 | 08:20:00 | 17:05:00 |
+-----------+------------+-----------+----------+
--------------
select matricule,
mois,
semaine,
sec_to_time(sum(duree)) as duree
from ( select matricule,
date_format(`date`, '%Y-%m') as mois,
date_format(`date`, '%Y-%v') as semaine,
time_to_sec(timediff(endtime, starttime)) as duree
from calendrier
order by matricule
) as x
group by matricule, mois, semaine
--------------
+-----------+---------+---------+----------+
| matricule | mois | semaine | duree |
+-----------+---------+---------+----------+
| 12 | 2017-05 | 2017-21 | 09:10:00 |
| 12 | 2017-05 | 2017-22 | 26:55:00 |
| 12 | 2017-06 | 2017-22 | 36:45:00 |
| 12 | 2017-06 | 2017-23 | 09:10:00 |
| 25 | 2017-05 | 2017-21 | 08:30:00 |
| 25 | 2017-05 | 2017-22 | 27:40:00 |
| 25 | 2017-06 | 2017-22 | 36:30:00 |
| 25 | 2017-06 | 2017-23 | 08:45:00 |
+-----------+---------+---------+----------+
--------------
COMMIT
--------------
--------------
SET AUTOCOMMIT = 1
--------------
Appuyez sur une touche pour continuer... |
Partager