呵呵,我又来问问题了,唉!人笨,最后两个一起问了,大家多帮帮忙,最好是sql2000中,2005里面好多都不支持的第一个问题:求循环
有sql数据表tb  
no  select text     1     1     温度    
1     1     气压      
1     0     天气      
1     1     水分  
1     0     压力        
26    1     气压    
26    1     水分    
26    0     天气            
14    1     天气  
14    0     湿度  
14    1     压力     
2     1     湿度 
2     0     温度 
    
……  (其中select中1代表条件,0代表结论) 语句表达循环是: 
if a and b then c 
-----if c then d 
-----if d then b 得到结果id xunhuan  xuhuan1
1   14       2也就是说
对于no1来说,就是温度,气压,水分推出天气和压力 
对于no14来说,就是天气和压力推出湿度 
对于no2来说,就是湿度推出温度这样判no14和no2对于no1造成了循环问题2:求矛盾
有sql数据表tb  
no  select text1   text2     1     1     温度     高  
1     1     气压     高 
1     0     天气     高 
1     1     水分     正常
1     0     压力     高   
26    1     气压     高
26    1     水分     高
26    0     天气     高       
14    1     水分     正常
14    0     天气     低
14    1     温度     高
14    1     气压     高 
14    0     压力     高
……  (其中select中1代表条件,0代表结论) 语句表达循环是: 
if a and b then c=c1
if a and b then c=c2
 
得到结果id maodun  
1   14       也就是说
对于no1来说,就是温度=高,气压=高,水分=正常推出天气=高和压力=高 
对于no14来说,就是温度=高,气压=高,水分=正常推出天气=低和压力=高这样判no14对于no1造成了矛盾

解决方案 »

  1.   

    把TEXT1+TEXT2变成原来的TEXT不就行了,其它一样。
      

  2.   

    1.
    create table tl(nn int,ss int,tt varchar(10))
    insert tl select 1,     1,     '温度'    
    union select 1,     1,     '气压'      
    union select 1,     0,     '天气'      
    union select 1,     1,     '水分'  
    union select 1,     0,     '压力'        
    union select 26,    1,     '气压'    
    union select 26,    1,     '水分'    
    union select 26,    0,     '天气'            
    union select 14,    1,     '水分'  
    union select 14,    0,     '湿度'  
    union select 14,    1,     '温度'    
    union select 14,    1,     '气压' 
    union select 2 ,    1,     '湿度' 
    union select 2 ,    0,     '天气'     
    go
    select distinct nn,ann,bnn from tl a,
    (select distinct a.nn ann,b.nn bnn  from tl a,tl b
    where a.nn<>b.nn and not exists(select 1 from 
    (select * from tl where ss = 0 and nn = a.nn) c full join 
    (select * from tl where ss = 1 and nn = b.nn) d on c.tt = b.tt
    where c.nn is null or d.nn is null)) b
    where nn <> ann and nn <> bnn 
    and not exists(select 1 from 
    (select * from tl where ss = 1 and nn=a.nn) c full join 
    (select * from tl where ss = 1 and nn =b.ann) d on c.tt = d.tt
    where c.nn is null or d.nn is null)
    and not exists(select 1 from 
    (select * from tl where ss = 0 and nn=a.nn) c right join 
    (select * from tl where ss = 0 and nn =b.bnn) d on c.tt = d.tt
    where d.nn is null)
    /*
    nn          ann         bnn         
    ----------- ----------- ----------- 
    1           14          2
    */
    go
    drop table tl
      

  3.   

    2.create table tl(nn int,ss int,tt1 varchar(10),tt2 varchar(10))select distinct a.nn as no1,b.nn as no2 
    from tl a,tl b 
    where a.nn <> b.nn
    and not exists(select 1 from 
    (select * from tl where no=a.nn and ss=1) c full join 
    (select * from tl where no=b.nn and ss=1) d
     on c.tt1+c.tt2 = d.tt1+d.tt2 where c.nn is null or d.nn is null)
    and exists(select 1 from 
    (select * from tl where no=a.nn and ss=0) c full join 
    (select * from tl where no=b.nn and ss=0) d
     on c.tt1+c.tt2 = d.tt1+d.tt2 where c.nn is null or d.nn is null)
      

  4.   

    恩,太谢谢cson了,第二个有个小缺陷就是会出现1  14
    14  1这样的情况
      

  5.   

    where a.nn <> b.nn
    ==>
    where a.nn < b.nn
      

  6.   

    5、6楼的貌似是通过数据和结果套SQL语句,没有什么实用价值。
      

  7.   

    create table tl(nn int,ss int,tt varchar(10))
    insert tl select 1,     1,     '温度'    
    union select 1,     1,     '气压'      
    union select 1,     0,     '天气'      
    union select 1,     1,     '水分'  
    union select 1,     0,     '压力'        
    union select 26,    1,     '气压'    
    union select 26,    1,     '水分'    
    union select 26,    0,     '天气'            
    union select 14,    1,     '水分'  
    union select 14,    0,     '湿度'  
    union select 14,    1,     '温度'    
    union select 14,    1,     '气压' 
    union select 2 ,    1,     '湿度' 
    union select 2 ,    0,     '天气'     
    go--将测试数据照抄一份,将nn加上100
    insert tl select nn+100,ss,tt from tl
    go--正确的结果应该是:/*
    nn          ann         bnn         
    ----------- ----------- ----------- 
    1           14         2
    1           14         102
    1           114         2
    1           114         102
    101         14         2
    101         14         102
    101         114         2
    101         114         102
    */
    select distinct nn,ann,bnn from tl a,
    (select distinct a.nn ann,b.nn bnn  from tl a,tl b
    where a.nn<>b.nn and not exists(select 1 from 
    (select * from tl where ss = 0 and nn = a.nn) c full join 
    (select * from tl where ss = 1 and nn = b.nn) d on c.tt = b.tt
    where c.nn is null or d.nn is null)) b
    where nn <> ann and nn <> bnn 
    and not exists(select 1 from 
    (select * from tl where ss = 1 and nn=a.nn) c full join 
    (select * from tl where ss = 1 and nn =b.ann) d on c.tt = d.tt
    where c.nn is null or d.nn is null)
    and not exists(select 1 from 
    (select * from tl where ss = 0 and nn=a.nn) c right join 
    (select * from tl where ss = 0 and nn =b.bnn) d on c.tt = d.tt
    where d.nn is null)--语句得出的结果是:/*
    nn          ann         bnn         
    ----------- ----------- ----------- 
    1           14          2
    1           14          102
    1           14          114
    1           114         2
    1           114         14
    1           114         102
    2           102         1
    2           102         26
    2           102         101
    2           102         126
    14          114         2
    14          114         102
    26          126         1
    26          126         2
    26          126         101
    26          126         102
    101         14          2
    101         14          102
    101         14          114
    101         114         2
    101         114         14
    101         114         102
    102         2           1
    102         2           26
    102         2           101
    102         2           126
    114         14          2
    114         14          102
    126         26          1
    126         26          2
    126         26          101
    126         26          102
    */
    godrop table tl
      

  8.   

    小楼厉害,有一个输入错误,修正一下:
    on c.tt = b.tt
    ==》
    on c.tt = d.tt
    不过 
    14 114 2 和 114 14 2 应该属于正解。