在MySQL中以为需求需要在查询结果添加自增id,网上找的这个方法,亲测成功 mysql中没有类似的函数,但可以用变量实现: set @n = 0; select (@n := @n + 1) as id , 字段名 from 表名;