mysql实现方案:
写法一:方法1的写法就是声明了一个变量在外部,然后每行数据都为它自增。
SET @rownum = 0;
SELECT @rownum := @rownum +1 AS rownum ,v.id ,v.create_time FROM vehiclegas v ORDER BY v.create_time DESC ;
写法二 :
SELECT (@i:=@i+1) AS rownum , v.id , v.create_time
FROM
vehiclegas v,
(SELECT @i := 0) AS i
ORDER BY
v.create_time DESC
sqlserver实现方法:
1◆查询的SQL语句如下:
select row_number() over (order by name) as rowid, sysobjects.[name] from sysobjects
◆运行的结果:
rowid name
1 all_columns
2 all_objects
3 all_parameters
4 all_sql_modules
5 all_views