Generate an integer sequence in MySQL

前端 未结 16 2946
南旧
南旧 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:22

    If you were using Oracle, 'pipelined functions' would be the way to go. Unfortunately, MySQL has no such construct.

    Depending on the scale of the numbers you want sets of, I see two simple ways to go : you either populate a temporary table with just the numbers you need (possibly using memory tables populated by a stored procedure) for a single query or, up front, you build a big table that counts from 1 to 1,000,000 and select bounded regions of it.

提交回复
热议问题