有一个表 table id type num 1 A 2 2 B 1 3 c 2 4 d 1 5 e 3 现有要求 判断 table 中 如果 有 ( type=A and num<=2 的记录 并且也有 type=c and num<=2 记录 )则返回真 或者有 (type=1 and num<=1 )则返回真,
if exists(select 1 from tb where (type='a' and num<=2) and (type='c' and num<=2) or (type='1' and num<=1)) print 'true' else print 'false'
if exists(select 1 from table where ((type=A and num <=2) and (type=c and num <=2)) or (type=1 and num <=1)) return true else return false
if exists(select 1 from table where ((type=A and num <=2) and (type=c and num <=2)) or (type=1 and num <=1)) return true else return false
借用上面的老兄 if exists(select 1 from table where ((type=A and num <=2) and (type=c and num <=2)) or (type=1 and num <=1)) return true else return false
解答错误,,, 我的意思是说表中同时有 (type=A and num <=2) 的记录 和 (type=c and num <=2) 记录 这里一行代表一条记录 你们所写 (( type=A and num <=2) and (type=c and num <=2 )) 这是恒等于 false 的,没有一条记录的type即是A,又是C的
if ((exists(select 1 from test where type='a' and num<=2 ) and exists(select 1 from test where type='c' and num<=2)) or exists(select 1 from test where type='1' and num<=2)) print 'true' else print 'false' 这样才会正确
print 'true'
else
print 'false'
return true
else
return false
return true
else
return false
if exists(select 1 from table where ((type=A and num <=2) and (type=c and num <=2)) or (type=1 and num <=1))
return true
else
return false
我的意思是说表中同时有
(type=A and num <=2) 的记录 和
(type=c and num <=2) 记录
这里一行代表一条记录
你们所写 (( type=A and num <=2) and (type=c and num <=2 )) 这是恒等于 false 的,没有一条记录的type即是A,又是C的
if ((exists(select 1 from test where type='a' and num<=2 ) and
exists(select 1 from test where type='c' and num<=2)) or
exists(select 1 from test where type='1' and num<=2))
print 'true'
else
print 'false'
这样才会正确