
230 PUZZLE 58 GAPS—VERSION TWO
PUZZLE
58 GAPS—VERSION TWO
Here is a second version of the classic SQL programming problem of
finding gaps in a sequence. How many ways can you do it? Can you
make it better with SQL-92 and SQL-99 features?
CREATE TABLE Tickets
(buyer_name CHAR(5) NOT NULL,
ticket_nbr INTEGER DEFAULT 1 NOT NULL
CHECK (ticket_nbr > 0),
PRIMARY KEY (buyer_name, ticket_nbr));
INSERT INTO Tickets
VALUES ('a', 2), ('a', 3), ('a', 4),
('b', 4),
('c', 1), ('c', 2), ('c', 3), ('c', 4), ('c', 5),
('d', 1), ('d', 6), ('d', 7), ('d', 9),
('e', 10);
Answer #1
Tom Moreau, another well-known SQL author in Toronto, came up
with this solution that ...