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
| --------------
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 `t_employee`
--------------
--------------
CREATE TABLE `t_employee`
( `id` integer unsigned NOT NULL auto_increment primary key,
`employee_id` integer unsigned NOT NULL,
`n_employee` varchar(255) NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `t_employee` (`employee_id`,`n_employee`) values
(99,'Chris'),(100,'Adel'),(101,'Béatrice'), (102,'Amy')
--------------
--------------
select * from `t_employee`
--------------
+----+-------------+------------+
| id | employee_id | n_employee |
+----+-------------+------------+
| 1 | 99 | Chris |
| 2 | 100 | Adel |
| 3 | 101 | Béatrice |
| 4 | 102 | Amy |
+----+-------------+------------+
--------------
DROP TABLE IF EXISTS `t_affectation`
--------------
--------------
CREATE TABLE `t_affectation`
( `id_a` integer unsigned NOT NULL auto_increment primary key,
`employee_id` integer unsigned NOT NULL,
`id_service` integer unsigned NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `t_affectation` (`employee_id`, `id_service`) values
(1,12),(2,12),(3,12),(4,12)
--------------
--------------
select * from `t_affectation`
--------------
+------+-------------+------------+
| id_a | employee_id | id_service |
+------+-------------+------------+
| 1 | 1 | 12 |
| 2 | 2 | 12 |
| 3 | 3 | 12 |
| 4 | 4 | 12 |
+------+-------------+------------+
--------------
DROP TABLE IF EXISTS `t_service`
--------------
--------------
CREATE TABLE `t_service`
( `id_srv` integer unsigned NOT NULL primary key,
`libelle_srv` varchar(255) NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `t_service` (`id_srv`,`libelle_srv`) values
(12,'Finance')
--------------
--------------
select * from `t_service`
--------------
+--------+-------------+
| id_srv | libelle_srv |
+--------+-------------+
| 12 | Finance |
+--------+-------------+
--------------
DROP TABLE IF EXISTS `t_pointage`
--------------
--------------
CREATE TABLE `t_pointage`
( `employee_id` integer unsigned NOT NULL,
`date` date NOT NULL,
`time` time NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `t_pointage` (`employee_id`,`date`,`time`) values
(99, '2023-03-04', '09:10:53')
--------------
--------------
select * from `t_pointage`
--------------
+-------------+------------+----------+
| employee_id | date | time |
+-------------+------------+----------+
| 99 | 2023-03-04 | 09:10:53 |
+-------------+------------+----------+
--------------
drop view if exists `t_attendance`
--------------
--------------
create view `t_attendance` as
select t1.`employee_id`,
t2.`n_employee` as name,
t1.`date`,
t1.`time`,
t1.`status`,
t4.`libelle_srv` as service
from ( select `employee_id`,
`date`,
`time`,
'Présent' as status
from `t_pointage`
union
select `employee_id`,
current_date as 'date',
'00:00:00' as 'time',
'Absent' as status
from `t_employee` as t1
where not exists (select 1 from `t_pointage` as t2 where t2.employee_id = t1.employee_id)
) as t1
inner join `t_employee` as t2
on t2.employee_id = t1.employee_id
inner join `t_affectation` as t3
on t3.id_a = t2.id
inner join `t_service` as t4
on t4.id_srv = t3.id_service
--------------
--------------
select * from `t_attendance`
--------------
+-------------+----------+------------+----------+---------+---------+
| employee_id | name | date | time | status | service |
+-------------+----------+------------+----------+---------+---------+
| 99 | Chris | 2023-03-04 | 09:10:53 | Présent | Finance |
| 100 | Adel | 2023-03-04 | 00:00:00 | Absent | Finance |
| 101 | Béatrice | 2023-03-04 | 00:00:00 | Absent | Finance |
| 102 | Amy | 2023-03-04 | 00:00:00 | Absent | Finance |
+-------------+----------+------------+----------+---------+---------+
--------------
COMMIT
--------------
Appuyez sur une touche pour continuer... |