1.while语法
while 布尔表达式
{sql语句或语句块}
break --跳出本层循环
{sql语句或语句块}
continue --跳出本次循环
{sql语句或语句块}
2.while实例
样例数据
要求:如果3-15号的平均分小于85,则将3-15号没人加5分,如果3-15号的最高分超过100分跳出循环。
语句:
while (select avg([score]) from [Table_1] where id between 3 and
15)<85
begin
update [Table_1]
set score=score+5
where id between
3 and 15
if (select max(score) from [Table_1] where id between 3 and
15)>=100
break
end
执行结果:select * from [Table_1]