123456的不重复的四位数,我排出以下十个1234    1235    1236    1345    1346    1456
2345    2346    2456
3456但是用C(6,4)来算的话,是15个或许我排出的十字不对,或许我对C(6,4)的理解有误,谢谢大家帮我指出一下!

解决方案 »

  1.   

    ----------------------------------------------------------------
    -- Author  :fredrickhu(小F,向高手学习)
    -- Date    :2011-11-18 09:42:32
    -- Version:
    --      Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86) 
    -- Apr 22 2011 11:57:00 
    -- Copyright (c) Microsoft Corporation
    -- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)
    --
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    go 
    create table [tb]([id] int)
    insert [tb]
    select 1 union all
    select 2 union all
    select 3 union all
    select 4 union all
    select 5 union all
    select 6
    --------------开始查询--------------------------
    select
      a.id,b.id,c.id,d.id
    from
      tb a,tb b ,tb c ,tb d
    where
      a.id<b.id and b.id<c.id and c.id<d.id 
    ----------------结果----------------------------
    /* 
    (6 行受影响)
    id          id          id          id
    ----------- ----------- ----------- -----------
    1           2           3           4
    1           2           3           5
    1           2           3           6
    1           2           4           5
    1           2           4           6
    1           2           5           6
    1           3           4           5
    1           3           4           6
    1           3           5           6
    1           4           5           6
    2           3           4           5
    2           3           4           6
    2           3           5           6
    2           4           5           6
    3           4           5           6(15 行受影响)
    */
      

  2.   

    如果说的是不同大小的四位数。
    if object_id('[tb]') is not null drop table [tb]
    go 
    create table [tb]([id] int)
    insert [tb]
    select 1 union all
    select 2 union all
    select 3 union all
    select 4 union all
    select 5 union all
    select 6
    select LTRIM(a.[id])+LTRIM(b.[id])+LTRIM(c.[id])+LTRIM(d.[id])
    from [tb] a,[tb] b,[tb] c,[tb] d
    order by LTRIM(a.[id])+LTRIM(b.[id])+LTRIM(c.[id])+LTRIM(d.[id])
      

  3.   

    还有 
    1   2    4    3
    1   2    5    3 之类的
    根据排列组合应该是  C(6,1)*C(5,1)*C(4,1)*C(3,1)=6*5*4*3=360种