Mysql :

SELECT (@i:=@i+1) AS ind ,字段 FROM 表名 别名, (SELECT @i:=0) t WHERE `IsDeleted` = 0;

Oracle:

本就有rownum。可直接用:SELECT rownum,字段 FROM 表名;

SqlServer:

SELECT ROW_NUMBER() OVER(ORDER BY ID) ROWNU,字段 FROM 表名;

给表中所有数据重新排序

SELECT (SELECT COUNT(`Id`) FROM 表名 别名1 WHERE 别名1.`IsDeleted` = 0 AND 别名1.`Id` <= 别名2.`Id`) AS seq ,别名2.* FROM 表名 别名2 WHERE 别名2.`IsDeleted` = 0 AND 别名2.`WLTId` = 3;




05-14 08:23
查看更多