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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
| --------------
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 `vehicule`
--------------
--------------
CREATE TABLE `vehicule`
( `id` integer unsigned NOT NULL,
`actif` tinyint unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
insert into `vehicule` (`id`,`actif`) values
(58301, 1), (58302, 1), (58303, 1), (61301, 1), (61302, 1),
(62301, 1), (62302, 1), (62303, 1), (63301, 1), (63302, 1),
(64302, 1), (64303, 1), (64304, 1), (65301, 1), (65302, 1)
--------------
--------------
select * from vehicule
--------------
+-------+-------+
| id | actif |
+-------+-------+
| 58301 | 1 |
| 58302 | 1 |
| 58303 | 1 |
| 61301 | 1 |
| 61302 | 1 |
| 62301 | 1 |
| 62302 | 1 |
| 62303 | 1 |
| 63301 | 1 |
| 63302 | 1 |
| 64302 | 1 |
| 64303 | 1 |
| 64304 | 1 |
| 65301 | 1 |
| 65302 | 1 |
+-------+-------+
--------------
drop table if exists `assignation`
--------------
--------------
CREATE TABLE `assignation`
( `id` integer unsigned NOT NULL,
`heure_debut` time NOT NULL,
`heure_fin` time NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
insert into `assignation` (`id`,`heure_debut`,`heure_fin`) values
( 5, '11:00:00', '15:00:00'),
( 9, '06:45:00', '10:45:00'),
(11, '06:45:00', '12:45:00'),
(12, '07:30:00', '11:30:00'),
(14, '07:00:00', '10:30:00'),
(17, '08:00:00', '13:00:00'),
(21, '08:30:00', '12:30:00'),
(23, '07:30:00', '10:30:00'),
(25, '07:45:00', '12:15:00'),
(27, '06:45:00', '09:30:00'),
(29, '07:45:00', '10:00:00')
--------------
--------------
select * from `assignation`
--------------
+----+-------------+-----------+
| id | heure_debut | heure_fin |
+----+-------------+-----------+
| 5 | 11:00:00 | 15:00:00 |
| 9 | 06:45:00 | 10:45:00 |
| 11 | 06:45:00 | 12:45:00 |
| 12 | 07:30:00 | 11:30:00 |
| 14 | 07:00:00 | 10:30:00 |
| 17 | 08:00:00 | 13:00:00 |
| 21 | 08:30:00 | 12:30:00 |
| 23 | 07:30:00 | 10:30:00 |
| 25 | 07:45:00 | 12:15:00 |
| 27 | 06:45:00 | 09:30:00 |
| 29 | 07:45:00 | 10:00:00 |
+----+-------------+-----------+
--------------
drop table if exists `repvehicule`
--------------
--------------
CREATE TABLE `repvehicule`
( `id` integer unsigned NOT NULL auto_increment,
`id_assignation` integer unsigned NOT NULL,
`id_vehicule` integer unsigned NOT NULL,
`date_rep` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
insert into `repvehicule` (`id_assignation`,`id_vehicule`,`date_rep`) values
( 5, 65301, '2016-01-26'),
( 9, 65301, '2016-01-26'),
(11, 65302, '2016-01-26'),
(12, 64302, '2016-01-26'),
(14, 64303, '2016-01-26'),
(17, 62302, '2016-01-26'),
(21, 62301, '2016-01-26'),
(23, 63302, '2016-01-26'),
(25, 63301, '2016-01-26'),
(27, 64304, '2016-01-26'),
(29, 62303, '2016-01-26')
--------------
--------------
select * from repvehicule
--------------
+----+----------------+-------------+------------+
| id | id_assignation | id_vehicule | date_rep |
+----+----------------+-------------+------------+
| 1 | 5 | 65301 | 2016-01-26 |
| 2 | 9 | 65301 | 2016-01-26 |
| 3 | 11 | 65302 | 2016-01-26 |
| 4 | 12 | 64302 | 2016-01-26 |
| 5 | 14 | 64303 | 2016-01-26 |
| 6 | 17 | 62302 | 2016-01-26 |
| 7 | 21 | 62301 | 2016-01-26 |
| 8 | 23 | 63302 | 2016-01-26 |
| 9 | 25 | 63301 | 2016-01-26 |
| 10 | 27 | 64304 | 2016-01-26 |
| 11 | 29 | 62303 | 2016-01-26 |
+----+----------------+-------------+------------+
--------------
select v.id,
rv.id_assignation,
a.heure_debut,
a.heure_fin
from vehicule as v
left outer join repvehicule as rv
on rv.id_vehicule = v.id
left outer join assignation as a
on a.id = rv.id_assignation
where v.actif = 1
and (rv.date_rep in ('2016-01-26')
or rv.date_rep is null)
order by v.id
--------------
+-------+----------------+-------------+-----------+
| id | id_assignation | heure_debut | heure_fin |
+-------+----------------+-------------+-----------+
| 58301 | NULL | NULL | NULL |
| 58302 | NULL | NULL | NULL |
| 58303 | NULL | NULL | NULL |
| 61301 | NULL | NULL | NULL |
| 61302 | NULL | NULL | NULL |
| 62301 | 21 | 08:30:00 | 12:30:00 |
| 62302 | 17 | 08:00:00 | 13:00:00 |
| 62303 | 29 | 07:45:00 | 10:00:00 |
| 63301 | 25 | 07:45:00 | 12:15:00 |
| 63302 | 23 | 07:30:00 | 10:30:00 |
| 64302 | 12 | 07:30:00 | 11:30:00 |
| 64303 | 14 | 07:00:00 | 10:30:00 |
| 64304 | 27 | 06:45:00 | 09:30:00 |
| 65301 | 5 | 11:00:00 | 15:00:00 |
| 65301 | 9 | 06:45:00 | 10:45:00 |
| 65302 | 11 | 06:45:00 | 12:45:00 |
+-------+----------------+-------------+-----------+
--------------
select tb1.id,
tb1.heure_debut,
tb1.heure_fin,
tb2.id as 'periode_id',
tb2.heure_debut as 'periode_debut',
tb2.heure_fin as 'periode_fin'
from assignation as tb1,
assignation as tb2
where not (tb1.heure_debut < tb2.heure_fin and tb1.heure_fin > tb2.heure_debut)
and tb1.id != tb2.id
--------------
+----+-------------+-----------+------------+---------------+-------------+
| id | heure_debut | heure_fin | periode_id | periode_debut | periode_fin |
+----+-------------+-----------+------------+---------------+-------------+
| 9 | 06:45:00 | 10:45:00 | 5 | 11:00:00 | 15:00:00 |
| 14 | 07:00:00 | 10:30:00 | 5 | 11:00:00 | 15:00:00 |
| 23 | 07:30:00 | 10:30:00 | 5 | 11:00:00 | 15:00:00 |
| 27 | 06:45:00 | 09:30:00 | 5 | 11:00:00 | 15:00:00 |
| 29 | 07:45:00 | 10:00:00 | 5 | 11:00:00 | 15:00:00 |
| 5 | 11:00:00 | 15:00:00 | 9 | 06:45:00 | 10:45:00 |
| 5 | 11:00:00 | 15:00:00 | 14 | 07:00:00 | 10:30:00 |
| 5 | 11:00:00 | 15:00:00 | 23 | 07:30:00 | 10:30:00 |
| 5 | 11:00:00 | 15:00:00 | 27 | 06:45:00 | 09:30:00 |
| 5 | 11:00:00 | 15:00:00 | 29 | 07:45:00 | 10:00:00 |
+----+-------------+-----------+------------+---------------+-------------+
--------------
COMMIT
--------------
--------------
SET AUTOCOMMIT = 1
--------------
Appuyez sur une touche pour continuer... |
Partager