Find the table number B > = number in the table but < then next entry b

I'm trying to understand the following: find the table number B > = number in the table but < then next entry b

Table A

5
10
21
20

Table B

8
12
16
23
40

The 5 entry in table A, I would like to return 8 b
For the 10 entry I would lke to return 12 b
21 entry I would like to return 23 b
20 entry I would like to return 23 b

Edited by: Withnoe October 5, 2012 09:19

Edited by: Withnoe October 5, 2012 10:54

CREATE TABLE TAB_A (CLASS # VARCHAR2 (10), THE NUMBER OF TERM);
CREATE TABLE TAB_B (CLASS # VARCHAR2 (10), THE NUMBER OF TERM);

INSERT INTO TAB_A VALUES ('BIOL 520', 201010);
INSERT INTO TAB_A VALUES ('BIOL 521', 201250);
INSERT INTO TAB_A VALUES ('BIOL 522', 200980);

INSERT INTO TAB_B VALUES ('BIOL 520', 201110);
INSERT INTO TAB_B VALUES ('BIOL 520', 201150);
INSERT INTO TAB_B VALUES ('BIOL 520', 201250);
INSERT INTO TAB_B VALUES ('BIOL 521', 201250);
INSERT INTO TAB_B VALUES ('BIOL 521', 201260);

SELECT MIN (TAB_B.TERM) TERM, TAB_B.CLASS # TO TAB_A, TAB_B
WHERE TAB_A.CLASS # = TAB_B.CLASS #.
AND TAB_B.TERM > TAB_A.TERM
GROUP TAB_B.CLASS #;

Please let us know if you need anything else. Thank you

Tags: Database

Similar Questions

Maybe you are looking for