Posted By

ktrout on 01/03/16


Tagged

mysql generator sequence


Versions (?)

mysql sequence generator ( decimal definition )


 / Published in: SQL
 

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

  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  

You need to login to post a comment.