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
| --------------
START TRANSACTION
--------------
--------------
DROP DATABASE IF EXISTS `base`
--------------
--------------
CREATE DATABASE IF NOT EXISTS `base`
DEFAULT CHARACTER SET `latin1`
DEFAULT COLLATE `latin1_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `projet`
--------------
--------------
CREATE TABLE `projet`
( `idProjet` integer unsigned NOT NULL auto_increment primary key,
`idClient` integer unsigned NOT NULL,
`nomProjet` varchar(255) NOT NULL,
`datedeb` date NOT NULL,
`datefin` date NULL,
`idResponsable` integer unsigned NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `projet` (`idProjet`,`idClient`,`nomProjet`,`datedeb`,`datefin`,`idResponsable`) VALUES
(1, 321, 'Développement du site web' , '2011-08-01', NULL, 1876),
(2, 321, 'Maintenance du systeme de ressources humaines' , '2012-05-01', '2012-07-23', 2231),
(3, 345, 'Développement du systeme de gestion de fournisseurs', '2011-11-01', NULL, 2231)
--------------
--------------
select *
from `projet`
--------------
+----------+----------+-----------------------------------------------------+------------+------------+---------------+
| idProjet | idClient | nomProjet | datedeb | datefin | idResponsable |
+----------+----------+-----------------------------------------------------+------------+------------+---------------+
| 1 | 321 | Développement du site web | 2011-08-01 | NULL | 1876 |
| 2 | 321 | Maintenance du systeme de ressources humaines | 2012-05-01 | 2012-07-23 | 2231 |
| 3 | 345 | Développement du systeme de gestion de fournisseurs | 2011-11-01 | NULL | 2231 |
+----------+----------+-----------------------------------------------------+------------+------------+---------------+
--------------
DROP TABLE IF EXISTS `etape`
--------------
--------------
CREATE TABLE `etape`
( `idProjet` integer unsigned NOT NULL,
`idEtape` integer unsigned NOT NULL,
`datedeb` date NOT NULL,
`datefin` date NULL,
CONSTRAINT `FK_PROJET` FOREIGN KEY (`idProjet`) REFERENCES `projet` (`idProjet`) ON DELETE CASCADE ON UPDATE CASCADE,
primary key (`idEtape`,`idProjet`)
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `etape` (`idProjet`,`idEtape`,`datedeb`,`datefin`) VALUES
(1, 1, '2011-07-01', '2011-09-01'),
(1, 2, '2011-09-02', '2011-11-30'),
(1, 3, '2011-12-01', '2012-07-07'),
(1, 4, '2012-07-08', NULL),
(2, 1, '2012-05-01', '2012-05-10'),
(2, 2, '2012-05-11', '2012-06-01'),
(2, 3, '2012-06-02', '2012-07-01'),
(2, 4, '2012-07-01', '2012-07-21'),
(2, 5, '2012-07-22', '2012-07-23'),
(3, 1, '2011-11-01', '2012-01-20'),
(3, 2, '2012-01-21', '2012-04-01'),
(3, 3, '2012-04-02', NULL)
--------------
--------------
select *
from `etape`
order by idProjet, idEtape
--------------
+----------+---------+------------+------------+
| idProjet | idEtape | datedeb | datefin |
+----------+---------+------------+------------+
| 1 | 1 | 2011-07-01 | 2011-09-01 |
| 1 | 2 | 2011-09-02 | 2011-11-30 |
| 1 | 3 | 2011-12-01 | 2012-07-07 |
| 1 | 4 | 2012-07-08 | NULL |
| 2 | 1 | 2012-05-01 | 2012-05-10 |
| 2 | 2 | 2012-05-11 | 2012-06-01 |
| 2 | 3 | 2012-06-02 | 2012-07-01 |
| 2 | 4 | 2012-07-01 | 2012-07-21 |
| 2 | 5 | 2012-07-22 | 2012-07-23 |
| 3 | 1 | 2011-11-01 | 2012-01-20 |
| 3 | 2 | 2012-01-21 | 2012-04-01 |
| 3 | 3 | 2012-04-02 | NULL |
+----------+---------+------------+------------+
--------------
select t3.nomProjet,
t3.datedeb as 'date début projet',
t3.datefin as 'date fin projet',
t1.idetape,
t1.datedeb as 'début précédente',
t1.datefin as 'fin précédente',
t2.idetape,
t2.datedeb as 'début suivante',
t2.datefin as 'fin suivante',
case when t1.datedeb > t1.datefin then "début étape précédente plus grande que fin étape précédente"
when t2.datedeb > t2.datefin then "début étape suivante plus grande que fin étape suivante"
when t1.datefin > t2.datedeb then "fin étape précédente plus grande que début étape suivante"
when t1.datedeb < t3.datedeb then "début étape précédente avant démarrage projet"
when t2.datedeb < t3.datedeb then "début étape suivante avant démarrage projet"
when t1.datefin > t3.datefin then "fin étape précédente après fin projet"
when t2.datefin > t3.datefin then "fin étape suivante après fin projet"
when t3.datedeb > t3.datefin then "début projet plus grande que fin projet"
else null end as test
from `etape` as t1
inner join `etape` as t2
on t2.idProjet = t1.idProjet
and t2.idEtape = ( select min(idEtape)
from `etape` as tx
where tx.idProjet = t1.idProjet
and tx.idEtape > t1.idEtape
)
inner join `projet` as t3
on t3.idProjet = t1.idProjet
order by t1.idProjet, t1.idEtape
--------------
+-----------------------------------------------------+-------------------+-----------------+---------+------------------+----------------+---------+----------------+--------------+-----------------------------------------------+
| nomProjet | date début projet | date fin projet | idetape | début précédente | fin précédente | idetape | début suivante | fin suivante | test |
+-----------------------------------------------------+-------------------+-----------------+---------+------------------+----------------+---------+----------------+--------------+-----------------------------------------------+
| Développement du site web | 2011-08-01 | NULL | 1 | 2011-07-01 | 2011-09-01 | 2 | 2011-09-02 | 2011-11-30 | début étape précédente avant démarrage projet |
| Développement du site web | 2011-08-01 | NULL | 2 | 2011-09-02 | 2011-11-30 | 3 | 2011-12-01 | 2012-07-07 | NULL |
| Développement du site web | 2011-08-01 | NULL | 3 | 2011-12-01 | 2012-07-07 | 4 | 2012-07-08 | NULL | NULL |
| Maintenance du systeme de ressources humaines | 2012-05-01 | 2012-07-23 | 1 | 2012-05-01 | 2012-05-10 | 2 | 2012-05-11 | 2012-06-01 | NULL |
| Maintenance du systeme de ressources humaines | 2012-05-01 | 2012-07-23 | 2 | 2012-05-11 | 2012-06-01 | 3 | 2012-06-02 | 2012-07-01 | NULL |
| Maintenance du systeme de ressources humaines | 2012-05-01 | 2012-07-23 | 3 | 2012-06-02 | 2012-07-01 | 4 | 2012-07-01 | 2012-07-21 | NULL |
| Maintenance du systeme de ressources humaines | 2012-05-01 | 2012-07-23 | 4 | 2012-07-01 | 2012-07-21 | 5 | 2012-07-22 | 2012-07-23 | NULL |
| Développement du systeme de gestion de fournisseurs | 2011-11-01 | NULL | 1 | 2011-11-01 | 2012-01-20 | 2 | 2012-01-21 | 2012-04-01 | NULL |
| Développement du systeme de gestion de fournisseurs | 2011-11-01 | NULL | 2 | 2012-01-21 | 2012-04-01 | 3 | 2012-04-02 | NULL | NULL |
+-----------------------------------------------------+-------------------+-----------------+---------+------------------+----------------+---------+----------------+--------------+-----------------------------------------------+
--------------
COMMIT
--------------
Appuyez sur une touche pour continuer... |
Partager