SQL SELECT to get the first N positive integers

前端 未结 10 1364

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

    Assuming you mean retrieve them from a table, here N is 10, assuming intcolumn is the column with numbers in it.

    SELECT intcolumn FROM numbers WHERE intcolumn > 0 LIMIT 10
    

    Edit: In case you were actually looking to get the mathematical set of positive numbers without a table, I would reconsider, it can be intensive (depending on the implementation). Commonly accepted practice seems to be to create a lookup table full of numbers, and then use the above query.

提交回复
热议问题