SQL SELECT to get the first N positive integers

前端 未结 10 1371

I need to get a result set containing the first N positive integers. Is it possible to use only standard SQL SELECT statement to get them (without any count table provided)?

10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 13:02

    A possible solution (admittedly not very elegant) is to use any table with a sufficiently large number of records.

    For the first 10 integers (using the mysql.help_relation, but any table would do), you could use the following query:

    SELECT  @N := @N +1 AS integers 
    FROM mysql.help_relation , (SELECT @N:=0) dum LIMIT 10;
    

    This could also be placed in a function taking Min and Max.

提交回复
热议问题