展开全部
从小到大
declare @test table(c1 varchar(50),c2 varchar(50),c3 varchar(50),c4 varchar(50),c5 varchar(50),c6 varchar(50),c7 varchar(50),c8 varchar(50),c9 varchar(50))
declare @i int = 1
while(@i <= 9)
begin
insert into @test select case when (1 <= @i) then CONVERT(varchar(50),@i) + ' * 1 = ' + CONVERT(varchar(50),@i*1) else '' end,
case when (2 <= @i) then CONVERT(varchar(50),@i) + ' * 2 = ' + CONVERT(varchar(50),@i*2) else '' end,
case when (3 <= @i) then CONVERT(varchar(50),@i) + ' * 3 = ' + CONVERT(varchar(50),@i*3) else '' end,
case when (4 <= @i) then CONVERT(varchar(50),@i) + ' * 4 = ' + CONVERT(varchar(50),@i*4) else '' end,
case when (5 <= @i) then CONVERT(varchar(50),@i) + ' * 5 = ' + CONVERT(varchar(50),@i*5) else '' end,
case when (6 <= @i) then CONVERT(varchar(50),@i) + ' * 6 = ' + CONVERT(varchar(50),@i*6) else '' end,
case when (7 <= @i) then CONVERT(varchar(50),@i) + ' * 7 = ' + CONVERT(varchar(50),@i*7) else '' end,
case when (8 <= @i) then CONVERT(varchar(50),@i) + ' * 8 = ' + CONVERT(varchar(50),@i*8) else '' end,
case when (9 <= @i) then CONVERT(varchar(50),@i) + ' * 9 = ' + CONVERT(varchar(50),@i*9) else '' end
set @i = @i + 1
end
select * from @test
c1 c2 c3 c4 c5 c6 c7 c8 c9
1 * 1 = 1
2 * 1 = 2 2 * 2 = 4
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36
7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49
8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81
从大到小
declare @test table(c1 varchar(50),c2 varchar(50),c3 varchar(50),c4 varchar(50),c5 varchar(50),c6 varchar(50),c7 varchar(50),c8 varchar(50),c9 varchar(50))
declare @i int = 9
while(@i >= 1)
begin
insert into @test select case when (1 <= @i) then CONVERT(varchar(50),@i) + ' * 1 = ' + CONVERT(varchar(50),@i*1) else '' end,
case when (2 <= @i) then CONVERT(varchar(50),@i) + ' * 2 = ' + CONVERT(varchar(50),@i*2) else '' end,
case when (3 <= @i) then CONVERT(varchar(50),@i) + ' * 3 = ' + CONVERT(varchar(50),@i*3) else '' end,
case when (4 <= @i) then CONVERT(varchar(50),@i) + ' * 4 = ' + CONVERT(varchar(50),@i*4) else '' end,
case when (5 <= @i) then CONVERT(varchar(50),@i) + ' * 5 = ' + CONVERT(varchar(50),@i*5) else '' end,
case when (6 <= @i) then CONVERT(varchar(50),@i) + ' * 6 = ' + CONVERT(varchar(50),@i*6) else '' end,
case when (7 <= @i) then CONVERT(varchar(50),@i) + ' * 7 = ' + CONVERT(varchar(50),@i*7) else '' end,
case when (8 <= @i) then CONVERT(varchar(50),@i) + ' * 8 = ' + CONVERT(varchar(50),@i*8) else '' end,
case when (9 <= @i) then CONVERT(varchar(50),@i) + ' * 9 = ' + CONVERT(varchar(50),@i*9) else '' end
set @i = @i - 1
end
select * from @test
c1 c2 c3 c4 c5 c6 c7 c8 c9
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81
8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64
7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49
6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
2 * 1 = 2 2 * 2 = 4
1 * 1 = 1
展开全部
declare @i smallint,@j smallint,@str varchar(100)
set @i=1
while @i<=9
begin
select @j=1,@str=''
while @j<=@i
select @str=@str
+cast(@j as char(1))
+'*'+cast(@i as char(1))
+'='+cast(@i*@j as char(2))
+space(2)
,@j=@j+1
print @str
set @i=@i+1
end
set @i=1
while @i<=9
begin
select @j=1,@str=''
while @j<=@i
select @str=@str
+cast(@j as char(1))
+'*'+cast(@i as char(1))
+'='+cast(@i*@j as char(2))
+space(2)
,@j=@j+1
print @str
set @i=@i+1
end
追问
从大到小排列的
9*9=81……9*1=1
.
.
.
1*1=1
像这样的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询