/ Published in: SQL
one cross join for each ai in definition of decimal number as sum(ai*10^i)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
DROP VIEW IF EXISTS digits_v; CREATE VIEW digits_v AS SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 ; -- get sequence 0..9 SELECT 10*a1.n + a0.n FROM digits_v a1 CROSS JOIN digits_v a0 WHERE (10*a1.n + a0.n) < 10 ORDER BY 10*a1.n + a0.n + 1 ;