I've got a database of movies, and I'd like a list of years where I don't have a movie for that year. So all I need is a list (1900 .. 2012) and then I can JOIN and IN and NOT IN on that all I want.
I've got:
CREATE PROCEDURE build_years(p1 SMALLINT)
BEGIN
CREATE TEMPORARY TABLE year (year SMALLINT(5) UNSIGNED);
label1: LOOP
INSERT INTO year VALUES (p1);
SET p1 = p1 + 1;
IF p1 > 2012 THEN LEAVE label1; END IF;
END LOOP;
END
But that seems so unSQL and only marginally less kludgy then running Python code to create the same table. I'd really like something that didn't use a stored procedure, didn't use looping and didn't use an actual table, in that order of concern.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…