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
| CREATE TABLE T
(CLEF INT,
NOM CHAR(1),
VALEUR INT)
INSERT INTO T VALUES (1, 'A', 10)
INSERT INTO T VALUES (2, 'B', 2)
INSERT INTO T VALUES (3, 'B', 8)
INSERT INTO T VALUES (4, 'A', 15)
INSERT INTO T VALUES (5, 'B', 20)
INSERT INTO T VALUES (6, 'A', 13)
SELECT TE.*
FROM T AS TE
INNER JOIN (SELECT T1.NOM, T1.VALEUR
FROM T AS T1
INNER JOIN T AS T2
ON T1.NOM = T2.NOM
AND T1.VALEUR > T2.VALEUR
GROUP BY T1.NOM, T1.VALEUR
HAVING COUNT(*) <= 2) AS TI
ON TE.NOM = TI.NOM
AND TE.VALEUR = TI.VALEUR
ORDER BY TE.NOM, TE.VALEUR
CLEF NOM VALEUR
----------- ---- -----------
6 A 13
4 A 15
3 B 8
5 B 20 |
Partager