In Python if I wanted a sequence from 0 - 9 (inclusive) I would use xrange(0,10) . Is there a way I can do this in MySQL?
解决方案
Since there is no such thing as xrange, one could use a separate table stored with integer (as previously answered), or just make a stored procedure to do the job:
DROP PROCEDURE IF EXISTS xrange;
DELIMITER //
CREATE PROCEDURE xrange(x INT, y INT)
BEGIN
DECLARE i INT DEFAULT x;
CREATE TEMPORARY TABLE xrange_tmp (c1 INT);
WHILE i < y DO
INSERT INTO xrange_tmp VALUES (i);
SET i = i + 1;
END WHILE;
END;
//
Usage:
CALL xrange(-2,10);
SELECT c1 FROM xrange_tmp;
DROP TABLE xrange_tmp;
The above is obviously going to be slower than creating a ready table with integers. It's more flexible though.