while 循环使用 min 聚合函数
DECLARE @ID AS INT;
SET @ID = (SELECT MIN(ID) from TABLE);
WHILE @ID IS NOT NULL
BEGIN
PRINT @ID;
SET @ID = (SELECT MIN(ID) FROM TABLE WHERE ID > @ID);
END
DECLARE @ID AS INT;
SET @ID = (SELECT MIN(ID) from TABLE);
WHILE @ID IS NOT NULL
BEGIN
PRINT @ID;
SET @ID = (SELECT MIN(ID) FROM TABLE WHERE ID > @ID);
END