1、mysql 自动生成连续日期

  1. java
  2. @Param("countArr")String[] countArr
  3. sql
  4. select date_add(#{startTime},interval @i:=@i+1 day) as date
  5. from (
  6. select 1
  7. <foreach item="index" collection="countArr">
  8. union all select 1
  9. </foreach>
  10. ) as tmp,
  11. (select @i:= -1) t
  12. 例如:
  13. select date_add('2021-05-01',interval @i:=@i+1 day) as date
  14. from (
  15. select 1
  16. union all select 1
  17. ) as tmp,
  18. (select @i:= -1) t

image.png

2、mysql 自动生成连续数字

 select  @i:=@i+1  as num
             from (
                     select 1
                    union all select 1
                    union all select 1
                    union all select 1
                    union all select 1
             ) as tmp,
                     (select @i:= 0) t

image.png