SELECT field1, field2
FROM table 1
如何在查询结果中添加自动增量临时ID字段?
答案 0 :(得分:3)
在MySQL中试试这个:
SELECT @s:=@s+1 ,field1, field2
FROM table1,
(SELECT @s:= 0) AS s
<强> SQLFIDDLE DEMO 强>
在MSSQL中它将是
SELECT row_number() OVER (ORDER BY field1, field2) n,
field1, field2
FROM table1