您的位置:程序门 -> db2 -> 基础类



比较两个sql语句


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


比较两个sql语句
发表于:2007-11-06 23:15:23 楼主
比较两个sql语句,为什么输出不同?

db2   =>   select   sname,semail   from   student   where   exists(select   sid,count(*)   from   sc
  group   by   sid   having   count(*)> 5)错误的,可能是因为自查询里没有父查询里的列属性约束
db2   =>   select   sname,semail   from   student   where   sid   in   (select   sid   from   sc   group   b
y   sid   having   count(*)> 5)(正确的)
我个人理解第一个句子中子查询里没有父查询里的列属性约束,大家有什么看法

发表于:2007-11-15 00:57:421楼 得分:0
exists   的用法有问题各。
select       sname,semail       from       student       where       exists(select   *   from   (select   sc.sid   from   sc   group   by   sc.sid   having   count(*)> 5   )as   a   where   a.sid=student.sid)
发表于:2007-11-15 12:47:452楼 得分:0
exists   返回的是   true   or   false  
发表于:2007-11-20 09:59:103楼 得分:0
第一个语法错误.而不是你说的那个原因.
发表于:2007-11-20 15:19:024楼 得分:0
二楼的为正解


快速检索

最新资讯
热门点击