网站首页

家园论坛

老版论坛

家园博客

业界新闻

技术文档

下载中心

速查中心

图片中心

硬件资讯
上一篇:DB2中通用的存储过程分页程序 下一篇:SQLSERVER管理员必备DBCC命令
用T-SQL实现26选7的几种算法

来源:本站原创 作者: 添加日期:2007-11-29 6:27:30 点击次数:

题目详述:从数字0,1,2,3,4,....25这二十六个数字选出任何7个数字,数字不能有重复,用T-SQL实现这些数字中任意7个数字的所有组合列表

实现方法一:

declare @one int,@two int,@three int,@four int,@five int,@six int ,@seven int,@maxvalue int
set @maxvalue = 25
select  @one=1 
while  @one<=@maxvalue   
begin 
    select  @two=1 
    while  @two<=@maxvalue 
    begin 
        select  @three=1 
        while  @three<=@maxvalue 
        begin
            select @four = 1
            while @four < @maxvalue
            begin
                select @five = 1
              while @five < @maxvalue
                begin   
                      select @six = 1
                  while @six < @maxvalue
                    begin   
                        select @seven = 1
                      while @seven < @maxvalue
                        begin   
                            print(cast(@one as varchar(3))+'-'+cast(@two as varchar(3))+'-'
                                    +cast(@three as varchar(3))+'-'+cast(@four as varchar(3))+'-'
                                    +cast(@five as varchar(3))+'-'+cast(@six as varchar(3))+'-'
                                    +cast(@seven as varchar(3))) 
                            select @seven = @seven + 1
                        end
                        select @six = @six + 1
                    end
                    select @five = @five +1
                end
                select @four = @four + 1
            end
            select  @three=@three+1 

本新闻共2页,当前在第1页  1  2  

 
设为首页 | 加入收藏 | 业务办理 | 友情链接 | 论坛版面 | 浙ICP备07502118号 |