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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
| --------------
SET AUTOCOMMIT = 0
--------------
--------------
START TRANSACTION
--------------
--------------
SET collation_connection = latin1_general_ci
--------------
--------------
DROP DATABASE IF EXISTS `base`
--------------
--------------
CREATE DATABASE `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,
`entreprise` varchar(255) not null,
`option` varchar(255) not null,
`chef` varchar(255) not null,
`personne` varchar(255) not null
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
insert into `test` (`entreprise`,`option`,`chef`,`personne`) values
('entr1', 'option1', 'chef 1', 'pers 1'), ('entr1', 'option1', 'chef 1', 'pers 2'), ('entr1', 'option1', 'chef 1', 'pers 3'),
('entr1', 'option1', 'chef 1', 'pers 4'), ('entr1', 'option1', 'chef 1', 'pers 5'), ('entr1', 'option1', 'chef 1', 'pers 6'),
('entr1', 'option1', 'chef 1', 'pers 7'), ('entr1', 'option1', 'chef 1', 'pers 8'),
('entr1', 'option1', 'chef 2', 'pers 9'), ('entr1', 'option1', 'chef 2', 'pers 10'), ('entr1', 'option1', 'chef 2', 'pers 11'),
('entr1', 'option1', 'chef 2', 'pers 12'), ('entr1', 'option1', 'chef 2', 'pers 13'), ('entr1', 'option1', 'chef 2', 'pers 14'),
('entr1', 'option1', 'chef 2', 'pers 15'), ('entr1', 'option1', 'chef 2', 'pers 16'),
('entr1', 'option2', 'chef 3', 'pers 17'), ('entr1', 'option2', 'chef 3', 'pers 18'), ('entr1', 'option2', 'chef 3', 'pers 19'),
('entr1', 'option2', 'chef 3', 'pers 20'), ('entr1', 'option2', 'chef 3', 'pers 21'), ('entr1', 'option2', 'chef 3', 'pers 22'),
('entr1', 'option2', 'chef 3', 'pers 23'), ('entr1', 'option2', 'chef 3', 'pers 24'),
('entr1', 'option2', 'chef 4', 'pers 25'), ('entr1', 'option2', 'chef 4', 'pers 26'), ('entr1', 'option2', 'chef 4', 'pers 27'),
('entr1', 'option2', 'chef 4', 'pers 28'), ('entr1', 'option2', 'chef 4', 'pers 29'), ('entr1', 'option2', 'chef 4', 'pers 30'),
('entr1', 'option2', 'chef 4', 'pers 31'), ('entr1', 'option2', 'chef 4', 'pers 32'),
('entr2', 'option3', 'chef 5', 'pers 33'), ('entr2', 'option3', 'chef 5', 'pers 34'), ('entr2', 'option3', 'chef 5', 'pers 35'),
('entr2', 'option3', 'chef 5', 'pers 36'), ('entr2', 'option3', 'chef 5', 'pers 37'), ('entr2', 'option3', 'chef 5', 'pers 38'),
('entr2', 'option3', 'chef 5', 'pers 39'), ('entr2', 'option3', 'chef 5', 'pers 40'),
('entr2', 'option3', 'chef 6', 'pers 41'), ('entr2', 'option3', 'chef 6', 'pers 42'), ('entr2', 'option3', 'chef 6', 'pers 43'),
('entr2', 'option3', 'chef 6', 'pers 44'), ('entr2', 'option3', 'chef 6', 'pers 45'), ('entr2', 'option3', 'chef 6', 'pers 46'),
('entr2', 'option3', 'chef 6', 'pers 47'), ('entr2', 'option3', 'chef 6', 'pers 48'),
('entr2', 'option4', 'chef 7', 'pers 49'), ('entr2', 'option4', 'chef 7', 'pers 50'), ('entr2', 'option4', 'chef 7', 'pers 51'),
('entr2', 'option4', 'chef 7', 'pers 52'), ('entr2', 'option4', 'chef 7', 'pers 53'), ('entr2', 'option4', 'chef 7', 'pers 54'),
('entr2', 'option4', 'chef 7', 'pers 55'), ('entr2', 'option4', 'chef 7', 'pers 56'),
('entr2', 'option4', 'chef 8', 'pers 57'), ('entr2', 'option4', 'chef 8', 'pers 58'), ('entr2', 'option4', 'chef 8', 'pers 59'),
('entr2', 'option4', 'chef 8', 'pers 60'), ('entr2', 'option4', 'chef 8', 'pers 61'), ('entr2', 'option4', 'chef 8', 'pers 62'),
('entr2', 'option4', 'chef 8', 'pers 63'), ('entr2', 'option4', 'chef 8', 'pers 64')
--------------
--------------
select * from `test`
--------------
+----+------------+---------+--------+----------+
| id | entreprise | option | chef | personne |
+----+------------+---------+--------+----------+
| 1 | entr1 | option1 | chef 1 | pers 1 |
| 2 | entr1 | option1 | chef 1 | pers 2 |
| 3 | entr1 | option1 | chef 1 | pers 3 |
| 4 | entr1 | option1 | chef 1 | pers 4 |
| 5 | entr1 | option1 | chef 1 | pers 5 |
| 6 | entr1 | option1 | chef 1 | pers 6 |
| 7 | entr1 | option1 | chef 1 | pers 7 |
| 8 | entr1 | option1 | chef 1 | pers 8 |
| 9 | entr1 | option1 | chef 2 | pers 9 |
| 10 | entr1 | option1 | chef 2 | pers 10 |
| 11 | entr1 | option1 | chef 2 | pers 11 |
| 12 | entr1 | option1 | chef 2 | pers 12 |
| 13 | entr1 | option1 | chef 2 | pers 13 |
| 14 | entr1 | option1 | chef 2 | pers 14 |
| 15 | entr1 | option1 | chef 2 | pers 15 |
| 16 | entr1 | option1 | chef 2 | pers 16 |
| 17 | entr1 | option2 | chef 3 | pers 17 |
| 18 | entr1 | option2 | chef 3 | pers 18 |
| 19 | entr1 | option2 | chef 3 | pers 19 |
| 20 | entr1 | option2 | chef 3 | pers 20 |
| 21 | entr1 | option2 | chef 3 | pers 21 |
| 22 | entr1 | option2 | chef 3 | pers 22 |
| 23 | entr1 | option2 | chef 3 | pers 23 |
| 24 | entr1 | option2 | chef 3 | pers 24 |
| 25 | entr1 | option2 | chef 4 | pers 25 |
| 26 | entr1 | option2 | chef 4 | pers 26 |
| 27 | entr1 | option2 | chef 4 | pers 27 |
| 28 | entr1 | option2 | chef 4 | pers 28 |
| 29 | entr1 | option2 | chef 4 | pers 29 |
| 30 | entr1 | option2 | chef 4 | pers 30 |
| 31 | entr1 | option2 | chef 4 | pers 31 |
| 32 | entr1 | option2 | chef 4 | pers 32 |
| 33 | entr2 | option3 | chef 5 | pers 33 |
| 34 | entr2 | option3 | chef 5 | pers 34 |
| 35 | entr2 | option3 | chef 5 | pers 35 |
| 36 | entr2 | option3 | chef 5 | pers 36 |
| 37 | entr2 | option3 | chef 5 | pers 37 |
| 38 | entr2 | option3 | chef 5 | pers 38 |
| 39 | entr2 | option3 | chef 5 | pers 39 |
| 40 | entr2 | option3 | chef 5 | pers 40 |
| 41 | entr2 | option3 | chef 6 | pers 41 |
| 42 | entr2 | option3 | chef 6 | pers 42 |
| 43 | entr2 | option3 | chef 6 | pers 43 |
| 44 | entr2 | option3 | chef 6 | pers 44 |
| 45 | entr2 | option3 | chef 6 | pers 45 |
| 46 | entr2 | option3 | chef 6 | pers 46 |
| 47 | entr2 | option3 | chef 6 | pers 47 |
| 48 | entr2 | option3 | chef 6 | pers 48 |
| 49 | entr2 | option4 | chef 7 | pers 49 |
| 50 | entr2 | option4 | chef 7 | pers 50 |
| 51 | entr2 | option4 | chef 7 | pers 51 |
| 52 | entr2 | option4 | chef 7 | pers 52 |
| 53 | entr2 | option4 | chef 7 | pers 53 |
| 54 | entr2 | option4 | chef 7 | pers 54 |
| 55 | entr2 | option4 | chef 7 | pers 55 |
| 56 | entr2 | option4 | chef 7 | pers 56 |
| 57 | entr2 | option4 | chef 8 | pers 57 |
| 58 | entr2 | option4 | chef 8 | pers 58 |
| 59 | entr2 | option4 | chef 8 | pers 59 |
| 60 | entr2 | option4 | chef 8 | pers 60 |
| 61 | entr2 | option4 | chef 8 | pers 61 |
| 62 | entr2 | option4 | chef 8 | pers 62 |
| 63 | entr2 | option4 | chef 8 | pers 63 |
| 64 | entr2 | option4 | chef 8 | pers 64 |
+----+------------+---------+--------+----------+
--------------
drop view if exists `vue`
--------------
--------------
create view `vue` as
select col1, col2, col3, group_concat(col4) as col4
from ( select concat(t1.`entreprise`, ':') as col1,
concat(t1.`option`, ':') as col2,
concat(t1.`chef`, ':') as col3,
t1.`personne` as col4,
((count(case when t1.id < t2.id then 1 else 0 end) -1) div 3) +1 as rang
from test as t1
left outer join test as t2
on t2.entreprise = t1.entreprise
and t2.option = t1.option
and t2.chef = t1.chef
and t2.id <= t1.id
group by t1.`entreprise`, t1.`option`, t1.`chef`, t1.`personne`
) as x
group by col1,col2,col3,rang
--------------
--------------
select * from vue
--------------
+--------+----------+---------+-------------------------+
| col1 | col2 | col3 | col4 |
+--------+----------+---------+-------------------------+
| entr1: | option1: | chef 1: | pers 1,pers 2,pers 3 |
| entr1: | option1: | chef 1: | pers 4,pers 5,pers 6 |
| entr1: | option1: | chef 1: | pers 7,pers 8 |
| entr1: | option1: | chef 2: | pers 11,pers 9,pers 10 |
| entr1: | option1: | chef 2: | pers 12,pers 13,pers 14 |
| entr1: | option1: | chef 2: | pers 15,pers 16 |
| entr1: | option2: | chef 3: | pers 17,pers 18,pers 19 |
| entr1: | option2: | chef 3: | pers 20,pers 21,pers 22 |
| entr1: | option2: | chef 3: | pers 23,pers 24 |
| entr1: | option2: | chef 4: | pers 27,pers 25,pers 26 |
| entr1: | option2: | chef 4: | pers 28,pers 29,pers 30 |
| entr1: | option2: | chef 4: | pers 31,pers 32 |
| entr2: | option3: | chef 5: | pers 33,pers 34,pers 35 |
| entr2: | option3: | chef 5: | pers 36,pers 37,pers 38 |
| entr2: | option3: | chef 5: | pers 39,pers 40 |
| entr2: | option3: | chef 6: | pers 43,pers 41,pers 42 |
| entr2: | option3: | chef 6: | pers 44,pers 45,pers 46 |
| entr2: | option3: | chef 6: | pers 47,pers 48 |
| entr2: | option4: | chef 7: | pers 49,pers 50,pers 51 |
| entr2: | option4: | chef 7: | pers 52,pers 53,pers 54 |
| entr2: | option4: | chef 7: | pers 55,pers 56 |
| entr2: | option4: | chef 8: | pers 59,pers 57,pers 58 |
| entr2: | option4: | chef 8: | pers 60,pers 61,pers 62 |
| entr2: | option4: | chef 8: | pers 63,pers 64 |
+--------+----------+---------+-------------------------+
--------------
select col1, col2, col3, col4
from ( select if(col1=@p1,'',col1) as col1,
if(col2=@p2,'',col2) as col2,
if(col3=@p3,'',col3) as col3,
col4,
@p1:=col1,@p2:=col2,@p3:=col3
from vue
cross join (select @p1:='',@p2:='',@p3:='') as x
) as y
--------------
+--------+----------+---------+-------------------------+
| col1 | col2 | col3 | col4 |
+--------+----------+---------+-------------------------+
| entr1: | option1: | chef 1: | pers 1,pers 2,pers 3 |
| | | | pers 4,pers 5,pers 6 |
| | | | pers 7,pers 8 |
| | | chef 2: | pers 11,pers 9,pers 10 |
| | | | pers 12,pers 13,pers 14 |
| | | | pers 15,pers 16 |
| | option2: | chef 3: | pers 17,pers 18,pers 19 |
| | | | pers 20,pers 21,pers 22 |
| | | | pers 23,pers 24 |
| | | chef 4: | pers 27,pers 25,pers 26 |
| | | | pers 28,pers 29,pers 30 |
| | | | pers 31,pers 32 |
| entr2: | option3: | chef 5: | pers 33,pers 34,pers 35 |
| | | | pers 36,pers 37,pers 38 |
| | | | pers 39,pers 40 |
| | | chef 6: | pers 43,pers 41,pers 42 |
| | | | pers 44,pers 45,pers 46 |
| | | | pers 47,pers 48 |
| | option4: | chef 7: | pers 49,pers 50,pers 51 |
| | | | pers 52,pers 53,pers 54 |
| | | | pers 55,pers 56 |
| | | chef 8: | pers 59,pers 57,pers 58 |
| | | | pers 60,pers 61,pers 62 |
| | | | pers 63,pers 64 |
+--------+----------+---------+-------------------------+
--------------
COMMIT
--------------
--------------
SET AUTOCOMMIT = 1
--------------
Appuyez sur une touche pour continuer... |
Partager