1.声明变量
    //关键字 @变量名 类型
    declare @变量名 varchar(20)
    declare @变量名 int,@变量名2,varchar(20)
    //给变量赋值,每次只能为一个变量赋值
    set @变量名=值
    //以文本方式打印
    print (@变量名)
    print (‘HALLO WORLD’)

    //select赋值 以表格的形式 可以同时赋值多个变量
    declare @A int,@B varchar(20)
    select @A=10,@B=’3’
    //以表格的形式输出多个值
    select @A,@B

    2.全局变量
    全局变量也称为系统变量,系统变量是不可以手动生成的
    ![0L0S1I7~8$@$OQ9BEREWQP.png
    3.条件

    1. declare @avg int;
    2. select @avg=AVG(列名) from 表名
    3. if(@avg>60)
    4. begin
    5. print ('平均分大于60')
    6. end
    7. else
    8. begin
    9. print ('平均分小于60')
    10. end

    4.循环
    while(条件)
    begin
    循环体
    递增值
    end

    5.case when then结构
    //区间判断
    select *, ‘别名’=case
    when 条件1 then ‘满足就返回这个值给case’
    when 条件2 then ‘满足就返回这个值给case’
    ……
    else ‘没有符合的条件返回这个值’
    end
    from 表名

    //等值判断
    select *, ‘别名’=case 列名
    when 条件1 then ‘满足就返回这个值给case’
    when 条件2 then ‘满足就返回这个值给case’
    ……
    else ‘没有符合的条件返回这个值’
    end
    from 表名