Created
March 11, 2015 16:14
-
-
Save lucas-tulio/a7071c1dab334d4adf6a to your computer and use it in GitHub Desktop.
Generates a list of numbers in MySQL without using tables, loops or procedures
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
select | |
t8.num as bit8, t7.num as bit7, t6.num as bit6, t5.num as bit5, t4.num as bit4, t3.num as bit3, t2.num as bit2, t1.num as bit1, | |
(t1.num * 1) + (t2.num * 2) + (t3.num * 4) + (t4.num * 8) + (t5.num * 16) + (t6.num * 32) + (t7.num * 64) + (t8.num * 128) as soma | |
from ( | |
((select 0 num) union all (select 1 num)) t1 | |
cross join | |
((select 0 num) union all (select 1 num)) t2 | |
cross join | |
((select 0 num) union all (select 1 num)) t3 | |
cross join | |
((select 0 num) union all (select 1 num)) t4 | |
cross join | |
((select 0 num) union all (select 1 num)) t5 | |
cross join | |
((select 0 num) union all (select 1 num)) t6 | |
cross join | |
((select 0 num) union all (select 1 num)) t7 | |
cross join | |
((select 0 num) union all (select 1 num)) t8 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: