Hive-SQL获取1~N连续数字序列列表(不用循环,用笛卡尔积)

WITH Digits AS (
    SELECT 0 AS Number
    UNION SELECT 1
    UNION SELECT 2
    UNION SELECT 3
    UNION SELECT 4
    UNION SELECT 5
    UNION SELECT 6
    UNION SELECT 7
    UNION SELECT 8
    UNION SELECT 9
)

SELECT chapter FROM (
	SELECT
	      (d4.Number * 10000)
	    + (d3.Number * 1000)
	    + (d2.Number * 100)
	    + (d1.Number * 10)
	    + d0.Number AS chapter
	FROM
	      Digits AS d4
	    , Digits AS d3
	    , Digits AS d2
	    , Digits AS d1
	    , Digits AS d0
	) t1
WHERE chapter > 0 AND chapter <= 20000
GROUP BY chapter
ORDER BY chapter

运行结果:1 ~ 20000

你可能感兴趣的:(Hive,mysql,hive,sql)