Create a view with column num_rows - MySQL

后端 未结 7 1476
[愿得一人]
[愿得一人] 2020-12-10 06:41

I need to create a view that has a column named row_num where it will be inserted the row number, just like an auto increment in a normal table.

Let\'s say I\'ve thi

7条回答
  •  孤街浪徒
    2020-12-10 07:20

    Adding Row number to a query result - No View needed - One Query

    SELECT country, name, price, @ID := @ID + 1 AS row_num
    FROM testing,
         (SELECT @ID := 0) temp
    

    Add the following to your MySQL connectionString: Allow User Variables=True;

    Don't add "Cross Join" in your query to update your @ID variable.

    Caution: attempting to use this in a View results in: View's SELECT contains a variable or parameter

提交回复
热议问题