Generate an integer sequence in MySQL

前端 未结 16 2939
南旧
南旧 2020-11-22 06:47

I need to do a join with a table/result-set/whatever that has the integers n to m inclusive. Is there a trivial way to get that without just buildi

16条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 07:07

    try this.. it works for me in mysql version 8.0. you can modify below query according to your required range

    WITH recursive numbers AS (
        select 0 as Date
       union all
       select Date + 1
       from numbers
       where Date < 10)
    select * from numbers;
    

    and yes without creating a table as mentioned in your post

提交回复
热议问题