use mytools;

DROP TABLE IF EXISTS heights;
CREATE TABLE heights(id INTEGER, name CHAR(10), height INTEGER, room INTEGER);

INSERT INTO heights VALUES( 1,'person1', 150, 1000);
INSERT INTO heights VALUES( 2,'person2', 180, 1000);
INSERT INTO heights VALUES( 3,'person3', 200, 1000);
INSERT INTO heights VALUES( 4,'person4', 100, 1000);
INSERT INTO heights VALUES( 5,'person5', 130, 2000);
INSERT INTO heights VALUES( 6,'person6', 100, 2000);
INSERT INTO heights VALUES( 7,'person7', 110, 2000);
INSERT INTO heights VALUES( 8,'person8', 120, 2000);

SELECT *
FROM heights h1
WHERE 3 > (
           SELECT COUNT(DISTINCT height)
           FROM heights h2
           WHERE h2.height > h1.height
           AND h1.room = h2.room 
          );

