SQL SELECT to get the first N positive integers

前端 未结 10 1385

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:10

    If your database supports analytic windowing functions the following is simple works really well:

    SELECT  row_number() over (partition by 1 order by 1) numbers
    FROM SOME_TABLE
    LIMIT 2700;
    

    This statement returns a set of numbers from 1 to 2700.

提交回复
热议问题