数据库之流程控制语句

来源:互联网 发布:贪吃飒淘宝小店 编辑:程序博客网 时间:2024/05/15 12:58

一、if  else 语句

declare @avg floatselect @avg = avg(english) from scoreprint '平均分数' + convert(varchar(20),@avg)if(@avg > 60)beginprint '前三名'select top 3 sName,english from student inner join score on student.sId=score.studentId order by english descendelsebeginprint '后三名'select top 3 sName,english from student inner join score on student.sId=score.studentId order by english ascend

其中,begin和end相当于“{}”大括号

二、while语句

declare @i int set @i=1while (@i<1000000)begin set @i=@i+1print @iend


原创粉丝点击