How would I get the row number of a mysql output, for example:
select * from table
name age
David 12
Frank 13
I want to get the row number, like so:
select *, row_num from table
row name age
1 David 12
2 Frank 13
The row number on the left -- 1 through 7 -- not a part of the data itself.
答案 0 :(得分:1)
在mysql中,您必须使用User-Defined Variables
。
SELECT @rowno := @rowno + 1 AS row_no, *
FROM table
CROSS JOIN (SELECT @rowno := 0) t
-- ORDER BY age