mysql sequence generator ( decimal definition )


/ Published in: SQL
Save to your folder(s)

one cross join for each ai in definition of decimal number as sum(ai*10^i)


Copy this code and paste it in your HTML
  1. DROP VIEW IF EXISTS digits_v;
  2. CREATE VIEW digits_v
  3. AS
  4. SELECT 0 AS n
  5. UNION ALL
  6. SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL
  7. SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL
  8. SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9
  9. ;
  10.  
  11. -- get sequence 0..9
  12. SELECT 10*a1.n + a0.n
  13. FROM digits_v a1
  14. CROSS JOIN digits_v a0
  15. WHERE (10*a1.n + a0.n) < 10
  16. ORDER BY 10*a1.n + a0.n + 1
  17. ;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.