How to generate sequence number in MySQL view?

前端 未结 2 478
情话喂你
情话喂你 2021-01-24 15:32

I am using MySQL 5.6 under Linux.

I have a table to let user input a from-number and a to-number.

Then, there is a view to select some records from another table

2条回答
  •  -上瘾入骨i
    2021-01-24 16:07

    Yon can take a look to this question and the answer that I report here:

    There is no ranking functionality in MySQL. The closest you can get is to use a variable:

    SELECT t.*, 
           @rownum := @rownum + 1 AS rank
      FROM YOUR_TABLE t, 
           (SELECT @rownum := 0) r
    

    In this way you can add a row counter to your result.

提交回复
热议问题