Created
January 9, 2019 02:03
-
-
Save dhaninugraha/dae8c1582bd20611386deccb59828fae to your computer and use it in GitHub Desktop.
[SQL] generate a number sequence without external functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with ones as ( | |
select base.n from (values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9)) base(n) | |
), tens as ( | |
select 10 * ones.n as n from ones | |
), hundreds as ( | |
select 100 * ones.n as n from ones | |
--), thousands as ( | |
-- select 1000 * ones.n as n from ones | |
), num_series as ( | |
select | |
ones.n + tens.n + hundreds.n /*+ thousands.n*/ as n | |
from ones, tens, hundreds/*, thousands*/ | |
order by n asc | |
) | |
-- this will return a sequence of 0-999 | |
select n from num_series; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment