站点图标 久久日记本

SQL基础复习(3)-T-SQL

--变量定义

declare @i int
declare @name varchar(20)

--变量赋值

set @i = 1
select @name= name from person where id = 10
set @name = (select name from person where id = 11)
set @i = @i+1
print @i

--if else

if(@i>1)
begin
 print 'i大于1'
end
else
begin
 print 'i小于等于1'
end;

--case when

select name,birthday,salary,
 case
  when salary<2000 then '低收入'
  when salary<3000 then '中等收入'
  when salary<4000 then '高收入'
  else '超高收入'
 end '收入等级'
from person

--while循环

set @i = 1
while(@i<10)
begin
 print @i
 set @i = @i + 1
end;
退出移动版