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
| --------------
START TRANSACTION
--------------
--------------
set session collation_connection = "latin1_general_ci"
--------------
--------------
DROP DATABASE IF EXISTS `base`
--------------
--------------
CREATE DATABASE IF NOT EXISTS `base`
DEFAULT CHARACTER SET `latin1`
DEFAULT COLLATE `latin1_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `user`
--------------
--------------
CREATE TABLE `user`
( `id` integer unsigned NOT NULL auto_increment Primary key,
`nom` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
--------------
--------------
INSERT INTO `user` (`nom`) VALUES
('Un'),('Deux'),('Trois')
--------------
--------------
select * from `user`
--------------
+----+-------+
| id | nom |
+----+-------+
| 1 | Un |
| 2 | Deux |
| 3 | Trois |
+----+-------+
--------------
DROP TABLE IF EXISTS `test`
--------------
--------------
CREATE TABLE `test`
( `id` integer unsigned NOT NULL auto_increment Primary key,
`date` date NOT NULL,
`user_id` integer unsigned NOT NULL,
`periode` char(01) NOT NULL,
`tache_id` integer unsigned NULL,
CONSTRAINT `FK_01` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
--------------
--------------
INSERT INTO `test` (`date`,`user_id`,`periode`,`tache_id`) VALUES
('2020-12-14', 1, 'M', 01),('2020-12-14', 1, 'S', 02),('2020-12-14', 2, 'M', 03),('2020-12-14', 2, 'S', 04),('2020-12-14', 3, 'M', 05),('2020-12-14', 3, 'S', 06),
('2020-12-15', 1, 'M', 07),('2020-12-15', 1, 'S', 08),('2020-12-15', 2, 'M', 09),('2020-12-15', 2, 'S', 10),('2020-12-15', 3, 'M', 11),('2020-12-15', 3, 'S', 12),
('2020-12-16', 1, 'M', 13),('2020-12-16', 1, 'S', 14),('2020-12-16', 2, 'M', 15),('2020-12-16', 2, 'S', 16),('2020-12-16', 3, 'M', 17),('2020-12-16', 3, 'S', 18),
('2020-12-17', 1, 'M', 19),('2020-12-17', 1, 'S', NULL),('2020-12-17', 2, 'M', 21),('2020-12-17', 2, 'S', 22),('2020-12-17', 3, 'M', 23),('2020-12-17', 3, 'S', 24),
('2020-12-18', 1, 'M', 25),('2020-12-18', 1, 'S', 26),('2020-12-18', 2, 'M', 27),('2020-12-18', 2, 'S', 28),('2020-12-18', 3, 'M', 29),('2020-12-18', 3, 'S', 30),
('2020-12-21', 1, 'M', 31),('2020-12-21', 1, 'S', 32),('2020-12-21', 2, 'M', NULL),('2020-12-21', 2, 'S', NULL),('2020-12-21', 3, 'M', 35),('2020-12-21', 3, 'S', 36),
('2020-12-22', 1, 'M', 37),('2020-12-22', 1, 'S', 38),('2020-12-22', 2, 'M', 39),('2020-12-22', 2, 'S', 40),('2020-12-22', 3, 'M', 41),('2020-12-22', 3, 'S', 42),
('2020-12-23', 1, 'M', 43),('2020-12-23', 1, 'S', 44),('2020-12-23', 2, 'M', 45),('2020-12-23', 2, 'S', 46),('2020-12-24', 3, 'M', NULL),('2020-12-23', 3, 'S', 48),
('2020-12-24', 1, 'M', 49),('2020-12-24', 1, 'S', 50),('2020-12-24', 2, 'M', 51),('2020-12-24', 2, 'S', 52),('2020-12-24', 3, 'M', 53),('2020-12-24', 3, 'S', 54),
('2020-12-25', 1, 'M', 55),('2020-12-25', 1, 'S', 56),('2020-12-25', 2, 'M', 57),('2020-12-25', 2, 'S', 58),('2020-12-25', 3, 'M', 59),('2020-12-25', 3, 'S', 60)
--------------
--------------
select * from `test`
--------------
+----+------------+---------+---------+----------+
| id | date | user_id | periode | tache_id |
+----+------------+---------+---------+----------+
| 1 | 2020-12-14 | 1 | M | 1 |
| 2 | 2020-12-14 | 1 | S | 2 |
| 3 | 2020-12-14 | 2 | M | 3 |
| 4 | 2020-12-14 | 2 | S | 4 |
| 5 | 2020-12-14 | 3 | M | 5 |
| 6 | 2020-12-14 | 3 | S | 6 |
| 7 | 2020-12-15 | 1 | M | 7 |
| 8 | 2020-12-15 | 1 | S | 8 |
| 9 | 2020-12-15 | 2 | M | 9 |
| 10 | 2020-12-15 | 2 | S | 10 |
| 11 | 2020-12-15 | 3 | M | 11 |
| 12 | 2020-12-15 | 3 | S | 12 |
| 13 | 2020-12-16 | 1 | M | 13 |
| 14 | 2020-12-16 | 1 | S | 14 |
| 15 | 2020-12-16 | 2 | M | 15 |
| 16 | 2020-12-16 | 2 | S | 16 |
| 17 | 2020-12-16 | 3 | M | 17 |
| 18 | 2020-12-16 | 3 | S | 18 |
| 19 | 2020-12-17 | 1 | M | 19 |
| 20 | 2020-12-17 | 1 | S | NULL |
| 21 | 2020-12-17 | 2 | M | 21 |
| 22 | 2020-12-17 | 2 | S | 22 |
| 23 | 2020-12-17 | 3 | M | 23 |
| 24 | 2020-12-17 | 3 | S | 24 |
| 25 | 2020-12-18 | 1 | M | 25 |
| 26 | 2020-12-18 | 1 | S | 26 |
| 27 | 2020-12-18 | 2 | M | 27 |
| 28 | 2020-12-18 | 2 | S | 28 |
| 29 | 2020-12-18 | 3 | M | 29 |
| 30 | 2020-12-18 | 3 | S | 30 |
| 31 | 2020-12-21 | 1 | M | 31 |
| 32 | 2020-12-21 | 1 | S | 32 |
| 33 | 2020-12-21 | 2 | M | NULL |
| 34 | 2020-12-21 | 2 | S | NULL |
| 35 | 2020-12-21 | 3 | M | 35 |
| 36 | 2020-12-21 | 3 | S | 36 |
| 37 | 2020-12-22 | 1 | M | 37 |
| 38 | 2020-12-22 | 1 | S | 38 |
| 39 | 2020-12-22 | 2 | M | 39 |
| 40 | 2020-12-22 | 2 | S | 40 |
| 41 | 2020-12-22 | 3 | M | 41 |
| 42 | 2020-12-22 | 3 | S | 42 |
| 43 | 2020-12-23 | 1 | M | 43 |
| 44 | 2020-12-23 | 1 | S | 44 |
| 45 | 2020-12-23 | 2 | M | 45 |
| 46 | 2020-12-23 | 2 | S | 46 |
| 47 | 2020-12-24 | 3 | M | NULL |
| 48 | 2020-12-23 | 3 | S | 48 |
| 49 | 2020-12-24 | 1 | M | 49 |
| 50 | 2020-12-24 | 1 | S | 50 |
| 51 | 2020-12-24 | 2 | M | 51 |
| 52 | 2020-12-24 | 2 | S | 52 |
| 53 | 2020-12-24 | 3 | M | 53 |
| 54 | 2020-12-24 | 3 | S | 54 |
| 55 | 2020-12-25 | 1 | M | 55 |
| 56 | 2020-12-25 | 1 | S | 56 |
| 57 | 2020-12-25 | 2 | M | 57 |
| 58 | 2020-12-25 | 2 | S | 58 |
| 59 | 2020-12-25 | 3 | M | 59 |
| 60 | 2020-12-25 | 3 | S | 60 |
+----+------------+---------+---------+----------+
--------------
select t1.`nom`,
t2.`date`,
any_value(dayname(t2.`date`)) as jour,
any_value(`periode`) as periode,
sum(case when t2.tache_id is null then 0 else 1 end) as nbre
from `user` as t1
left outer join `test` as t2
on t2.user_id = t1.id
where t2.`date` between current_date() and current_date + interval 6 day
group by t1.`nom`, t2.`date`
having nbre <> 2
order by t1.`nom`
--------------
+-------+------------+----------+---------+------+
| nom | date | jour | periode | nbre |
+-------+------------+----------+---------+------+
| Deux | 2020-12-21 | lundi | M | 0 |
| Trois | 2020-12-23 | mercredi | S | 1 |
| Un | 2020-12-17 | jeudi | M | 1 |
+-------+------------+----------+---------+------+
--------------
COMMIT
--------------
Appuyez sur une touche pour continuer... |
Partager