日期:2014-05-18 浏览次数:20650 次
DECLARE @NUMS TABLE(NUM INT) INSERT INTO @NUMS SELECT NUMBER FROM MASTER..SPT_VALUES WHERE TYPE='P' AND NUMBER BETWEEN 0 AND 9 SELECT N1.NUM,N2.NUM,N3.NUM,N4.NUM,N5.NUM,N6.NUM,N7.NUM FROM @NUMS N1 INNER JOIN @NUMS N2 ON N1.NUM<>N2.NUM INNER JOIN @NUMS N3 ON N1.NUM<>N3.NUM AND N2.NUM<>N3.NUM INNER JOIN @NUMS N4 ON N1.NUM<>N4.NUM AND N2.NUM<>N4.NUM AND N3.NUM<>N4.NUM INNER JOIN @NUMS N5 ON N1.NUM<>N5.NUM AND N2.NUM<>N5.NUM AND N3.NUM<>N5.NUM AND N4.NUM<>N5.NUM INNER JOIN @NUMS N6 ON N1.NUM<>N6.NUM AND N2.NUM<>N6.NUM AND N3.NUM<>N6.NUM AND N4.NUM<>N6.NUM AND N5.NUM<>N6.NUM INNER JOIN @NUMS N7 ON N1.NUM<>N7.NUM AND N2.NUM<>N7.NUM AND N3.NUM<>N7.NUM AND N4.NUM<>N7.NUM AND N5.NUM<>N7.NUM AND N6.NUM<>N7.NUM WHERE N5.NUM*N6.NUM+N4.NUM*10*N6.NUM+N3.NUM*100*N6.NUM+N2.NUM*1000*N6.NUM+N1.NUM*10000*N6.NUM =N7.NUM+N7.NUM*10+N7.NUM*100+N7.NUM*1000+N7.NUM*10000+N7.NUM*100000 /* 9 5 2 3 8 7 6 SELECT 95238*7 --SELECT 95238*7 */
------解决方案--------------------
第二题
DECLARE @NUMS TABLE(NUM INT) INSERT INTO @NUMS SELECT NUMBER FROM MASTER..SPT_VALUES WHERE TYPE='P' AND NUMBER BETWEEN 0 AND 9 SELECT N1.NUM,N2.NUM,N3.NUM,N4.NUM,N5.NUM,N6.NUM FROM @NUMS N1 INNER JOIN @NUMS N2 ON N1.NUM<>N2.NUM INNER JOIN @NUMS N3 ON N1.NUM<>N3.NUM AND N2.NUM<>N3.NUM INNER JOIN @NUMS N4 ON N1.NUM<>N4.NUM AND N2.NUM<>N4.NUM AND N3.NUM<>N4.NUM INNER JOIN @NUMS N5 ON N1.NUM<>N5.NUM AND N2.NUM<>N5.NUM AND N3.NUM<>N5.NUM AND N4.NUM<>N5.NUM INNER JOIN @NUMS N6 ON N1.NUM<>N6.NUM AND N2.NUM<>N6.NUM AND N3.NUM<>N6.NUM AND N4.NUM<>N6.NUM AND N5.NUM<>N6.NUM WHERE N1.NUM*100000*2+N2.NUM*10000*2+N3.NUM*1000*2+N4.NUM*100*2+N5.NUM*10*2+N6.NUM*1*2 =N3.NUM*100000+N4.NUM*10000+N5.NUM*1000+N6.NUM*100+N1.NUM*10+N2.NUM*1 AND N3.NUM*100000*2+N4.NUM*10000*2+N5.NUM*1000*2+N6.NUM*100*2+N1.NUM*10*2+N2.NUM*1*2 =N5.NUM*100000+N6.NUM*10000+N1.NUM*1000+N2.NUM*100+N3.NUM*10+N4.NUM*1 /* 1 4 2 8 5 7 */
------解决方案--------------------
2. declare @tb table (num int) insert into @tb select number from master..spt_values where TYPE='p' and number between 0 and 9 select distinct a.num a,b.num b,c.num c,d.num d,e.num e,f.num f from @tb a ,@tb b,@tb c,@tb d ,@tb e,@tb f where (a.num*100000+b.num*10000+c.num*1000+d.num*100+e.num*10+f.num)*2= c.num*100000+d.num*10000+e.num*1000+f.num*100+a.num*10+b.num and (c.num*100000+d.num*10000+e.num*1000+f.num*100+a.num*10+b.num)*2= e.num*100000+f.num*10000+a.num*1000+b.num*100+c.num*10+d.num and a.num<>b.num and a.num<>c.num and a.num<>d.num and a.num<>e.num and b.num<>c.num and b.num<>d.num and b.num<>e.num and c.num<>d.num and c.num<>e.num and d.num<>e.num a b c d e f 1 4 2 8 5 7
------解决方案--------------------
两个都改一下
1. declare @tb table (num int) insert into @tb select number from master..spt_va