请问一下在mysql中,将查询一个语句的结果中增加一列ID字段并让其自动增长, 这怎么做到?

2024-11-27 17:52:24
推荐回答(3个)
回答1:

SELECT (SELECT COUNT(id) FROM srcTableName AS tbl1 WHERE tbl1.id<=tbl2.id) as
seq,field1,field2,...,fieldn
FROM srcTableName AS tbl2 ORDER BY 1 ;

回答2:

SELECT @rownum:=@rownum+1 AS 序号, a.* FROM t_user a ,(SELECT @rownum:=0) r;

回答3:

set @rownum=0;
select a.*, @rownum := @rownum +1 as id from a;