Get the row number in Mysql

  There is no function to get the row number in mysql, but we can get the row number by defining variables. Here is a simple example.

The data in the table is as follows:

Insert picture description here
Next, sort the price'price' and mark the row number, the sql is as follows:

SELECT 
  @rownum:= @rownum + 1 AS rownum,
	trade_name,
	price
FROM
  (SELECT @rownum := 0) t,`t_commodity_information`
ORDER BY
  price DESC;

The query result is as follows:
Insert picture description here
You can see that the row number has been marked for the data queried.

Guess you like

Origin blog.csdn.net/AnameJL/article/details/114135288