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
| CREATE TABLE T_EMPLOYE_EMP
(id_emp INT,
niv_emp INT,
num_emp INT)
INSERT INTO T_EMPLOYE_EMP VALUES (1, 3, 10)
INSERT INTO T_EMPLOYE_EMP VALUES (2, 4, 101)
INSERT INTO T_EMPLOYE_EMP VALUES (3, 4, 111)
INSERT INTO T_EMPLOYE_EMP VALUES (4, 4, 121)
INSERT INTO T_EMPLOYE_EMP VALUES (5, 3, 15)
INSERT INTO T_EMPLOYE_EMP VALUES (6, 4, 151)
INSERT INTO T_EMPLOYE_EMP VALUES (7, 4, 161)
INSERT INTO T_EMPLOYE_EMP VALUES (8, 4, 170)
SELECT E1.*, (SELECT MAX(E2.num_emp)
FROM T_EMPLOYE_EMP E2
WHERE E2.num_emp <= CEILING(CAST(E1.num_emp AS FLOAT) / 10.0) ) AS SUP
FROM T_EMPLOYE_EMP E1
WHERE NUM_EMP >= 100
id_emp niv_emp num_emp SUP
----------- ----------- ----------- -----------
2 4 101 10
3 4 111 10
4 4 121 10
6 4 151 15
7 4 161 15
8 4 170 15 |
Partager