我在一组数,从1至35 。我想要的结果是每一组七位数,并且每一组不能重复。

解决方案 »

  1.   

       protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                CreateNum();
            }
        }
        //在从1到20间随机生成6个互不相同的整数。
        public void CreateNum()
        {
            ArrayList MyArray = new ArrayList();
            Random random = new Random();
            string str = null;
           
            //循环的次数
            int Nums = 6;
            while (Nums > 0)
            {
                int i = random.Next(1, 9);
                if (!MyArray.Contains(i))
                {
                    if (MyArray.Count < 6)
                    {
                        MyArray.Add(i);
                    }            }
                Nums -= 1;
            }
            
            for (int j = 0; j <= MyArray.Count - 1; j++)
            {
                str += MyArray[j].ToString();
            }
            Response.Write(str);
        }
    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ws_hgo/archive/2009/05/09/4164277.aspx
      

  2.   

    http://blog.csdn.net/ws_hgo/archive/2009/05/09/4164277.aspx
      

  3.   


    --这个不可以吗
    select top 7 number
    from
    (
    select distinct  number  from master.dbo.spt_values
    where number between 1 and 35
    ) A order by newid()
      

  4.   

    这样也是OK的。SELECT  
    MAX(CASE WHEN (LO.NUMBER-1) % 7 = 0 THEN LO.NUMBER END) AS NUMBER1,  
    MAX(CASE WHEN (LO.NUMBER-1) % 7 = 1 THEN LO.NUMBER END) AS NUMBER2,
    MAX(CASE WHEN (LO.NUMBER-1) % 7 = 2 THEN LO.NUMBER END) AS NUMBER3,
    MAX(CASE WHEN (LO.NUMBER-1) % 7 = 3 THEN LO.NUMBER END) AS NUMBER4,
    MAX(CASE WHEN (LO.NUMBER-1) % 7 = 4 THEN LO.NUMBER END) AS NUMBER5,
    MAX(CASE WHEN (LO.NUMBER-1) % 7 = 5 THEN LO.NUMBER END) AS NUMBER6,
    MAX(CASE WHEN (LO.NUMBER-1) % 7 = 6 THEN LO.NUMBER END) AS NUMBER7
    FROM 
    (
    SELECT DISTINCT NUMBER 
    FROM  master.dbo.spt_values 
    WHERE NUMBER between 1 and 35) LO 
    GROUP BY (LO.NUMBER-1)/7
     
    /*
    1    2 3   4   5   6    7
    8    9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30 31 32 33 34 35
    */
      

  5.   

    declare @start int 
    set @start = 1
    declare @end int
    set @end = 35
    declare @level int
    set @level = 7;with cte as
    (
      select id = @start 
      union all
      select id = a.id +1 from cte a where a.id < @end
    )select id into # from ctecreate table result(col1 int,col2 int,col3 int,col4 int,col5 int,col6 int,col7 int)
    declare @px int 
    set @px = @start
    while @px < = @end-6
        begin
            declare @cn int
            set @cn = @px+6
            while @cn < = @end
    begin
    insert into result
    select *,col7 = @cn from
    (
        select top 6 id,px = row_number() over(order by id) from # where id>=@px order by id
    ) as T 
    PIVOT(MAX(id) FOR px IN([1],[2],[3],[4],[5],[6])) AS pvt
    set @cn = @cn+1
    end
    set @px = @px+1       
        end 
        
        
    select * from resultdrop table #
    drop table result