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
| --------------
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 `reservation`
--------------
--------------
CREATE TABLE `reservation`
( `num_reservation` integer unsigned NOT NULL auto_increment primary key,
`date_reservation` date NOT NULL,
`periode_deb` date NOT NULL,
`periode_fin` date NOT NULL,
`nom` varchar(255) NOT NULL,
`prenom` varchar(255) NOT NULL,
`num_chambre` integer unsigned NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
insert into `reservation` (`date_reservation`,`periode_deb`,`periode_fin`,`nom`,`prenom`,`num_chambre`) values
('2017-05-01', '2017-05-18', '2017-05-20', 'nom 01', 'prenom 01', 101),
('2017-05-02', '2017-05-21', '2017-05-25', 'nom 02', 'prenom 02', 101),
('2017-05-03', '2017-05-26', '2017-05-28', 'nom 03', 'prenom 03', 101),
('2017-05-04', '2017-05-29', '2017-05-31', 'nom 04', 'prenom 04', 101),
('2017-05-01', '2017-05-18', '2017-05-19', 'nom 11', 'prenom 11', 102),
('2017-05-02', '2017-05-20', '2017-05-22', 'nom 12', 'prenom 12', 102),
('2017-05-03', '2017-05-24', '2017-05-27', 'nom 13', 'prenom 13', 102),
('2017-05-04', '2017-05-28', '2017-05-31', 'nom 14', 'prenom 14', 102),
('2017-05-01', '2017-05-18', '2017-05-18', 'nom 21', 'prenom 21', 103),
('2017-05-02', '2017-05-19', '2017-05-21', 'nom 22', 'prenom 22', 103),
('2017-05-03', '2017-05-23', '2017-05-26', 'nom 23', 'prenom 23', 103),
('2017-05-04', '2017-05-27', '2017-05-31', 'nom 24', 'prenom 24', 103),
('2017-05-07', '2017-05-18', '2017-05-19', 'nom 31', 'prenom 31', 201),
('2017-05-07', '2017-05-20', '2017-05-21', 'nom 32', 'prenom 32', 201),
('2017-05-07', '2017-05-25', '2017-05-28', 'nom 33', 'prenom 33', 201),
('2017-05-07', '2017-05-29', '2017-05-31', 'nom 34', 'prenom 34', 201),
('2017-05-08', '2017-05-18', '2017-05-19', 'nom 41', 'prenom 41', 202),
('2017-05-08', '2017-05-20', '2017-05-22', 'nom 42', 'prenom 42', 202),
('2017-05-09', '2017-05-26', '2017-05-29', 'nom 43', 'prenom 43', 202),
('2017-05-09', '2017-05-30', '2017-05-31', 'nom 44', 'prenom 44', 202),
('2017-05-10', '2017-05-18', '2017-05-21', 'nom 51', 'prenom 51', 203),
('2017-05-10', '2017-05-22', '2017-05-24', 'nom 52', 'prenom 52', 203),
('2017-05-11', '2017-05-26', '2017-05-28', 'nom 53', 'prenom 53', 203),
('2017-05-11', '2017-05-29', '2017-05-31', 'nom 54', 'prenom 54', 203)
--------------
--------------
select * from `reservation`
--------------
+-----------------+------------------+-------------+-------------+--------+-----------+-------------+
| num_reservation | date_reservation | periode_deb | periode_fin | nom | prenom | num_chambre |
+-----------------+------------------+-------------+-------------+--------+-----------+-------------+
| 1 | 2017-05-01 | 2017-05-18 | 2017-05-20 | nom 01 | prenom 01 | 101 |
| 2 | 2017-05-02 | 2017-05-21 | 2017-05-25 | nom 02 | prenom 02 | 101 |
| 3 | 2017-05-03 | 2017-05-26 | 2017-05-28 | nom 03 | prenom 03 | 101 |
| 4 | 2017-05-04 | 2017-05-29 | 2017-05-31 | nom 04 | prenom 04 | 101 |
| 5 | 2017-05-01 | 2017-05-18 | 2017-05-19 | nom 11 | prenom 11 | 102 |
| 6 | 2017-05-02 | 2017-05-20 | 2017-05-22 | nom 12 | prenom 12 | 102 |
| 7 | 2017-05-03 | 2017-05-24 | 2017-05-27 | nom 13 | prenom 13 | 102 |
| 8 | 2017-05-04 | 2017-05-28 | 2017-05-31 | nom 14 | prenom 14 | 102 |
| 9 | 2017-05-01 | 2017-05-18 | 2017-05-18 | nom 21 | prenom 21 | 103 |
| 10 | 2017-05-02 | 2017-05-19 | 2017-05-21 | nom 22 | prenom 22 | 103 |
| 11 | 2017-05-03 | 2017-05-23 | 2017-05-26 | nom 23 | prenom 23 | 103 |
| 12 | 2017-05-04 | 2017-05-27 | 2017-05-31 | nom 24 | prenom 24 | 103 |
| 13 | 2017-05-07 | 2017-05-18 | 2017-05-19 | nom 31 | prenom 31 | 201 |
| 14 | 2017-05-07 | 2017-05-20 | 2017-05-21 | nom 32 | prenom 32 | 201 |
| 15 | 2017-05-07 | 2017-05-25 | 2017-05-28 | nom 33 | prenom 33 | 201 |
| 16 | 2017-05-07 | 2017-05-29 | 2017-05-31 | nom 34 | prenom 34 | 201 |
| 17 | 2017-05-08 | 2017-05-18 | 2017-05-19 | nom 41 | prenom 41 | 202 |
| 18 | 2017-05-08 | 2017-05-20 | 2017-05-22 | nom 42 | prenom 42 | 202 |
| 19 | 2017-05-09 | 2017-05-26 | 2017-05-29 | nom 43 | prenom 43 | 202 |
| 20 | 2017-05-09 | 2017-05-30 | 2017-05-31 | nom 44 | prenom 44 | 202 |
| 21 | 2017-05-10 | 2017-05-18 | 2017-05-21 | nom 51 | prenom 51 | 203 |
| 22 | 2017-05-10 | 2017-05-22 | 2017-05-24 | nom 52 | prenom 52 | 203 |
| 23 | 2017-05-11 | 2017-05-26 | 2017-05-28 | nom 53 | prenom 53 | 203 |
| 24 | 2017-05-11 | 2017-05-29 | 2017-05-31 | nom 54 | prenom 54 | 203 |
+-----------------+------------------+-------------+-------------+--------+-----------+-------------+
--------------
set @libre_deb = '2017-05-23'
--------------
--------------
set @libre_fin = '2017-05-24'
--------------
--------------
select *
from (
select t1.num_chambre, t1.periode_fin, t2.periode_deb
from reservation as t1
left outer join reservation as t2
on t2.num_chambre = t1.num_chambre
and t2.periode_deb > t1.periode_fin
group by t1.num_chambre, t1.periode_fin
order by t1.num_chambre, t1.periode_fin
) as x
where periode_fin < @libre_deb
and periode_deb > @libre_fin
--------------
+-------------+-------------+-------------+
| num_chambre | periode_fin | periode_deb |
+-------------+-------------+-------------+
| 201 | 2017-05-21 | 2017-05-25 |
| 202 | 2017-05-22 | 2017-05-26 |
+-------------+-------------+-------------+
--------------
COMMIT
--------------
--------------
SET AUTOCOMMIT = 1
--------------
Appuyez sur une touche pour continuer... |
Partager