先执行where a=t1.a and b=t1.b在执行(Select max(c) from t1 接着where c in(Select max(c)最后
Select * from t1

解决方案 »

  1.   

    学习
    估计要问微软开发sql的人了
      

  2.   

    基于条件的条件的....查询推敲一下对大家来说应该不是特别难的事,按照正常的程序逻辑的话, taiguang(银狐)说的好像有点道理,具体sql内部执行是不是这样子? 最好有高人指点
      

  3.   

    Select * from t1 where c in(Select max(c) from t1 where a=t1.a and b=t1.b)
    首先,把 刚才的 语句 改成 这样 对吗?Select * from t1 t1  where c in(Select max(c) from t1 t2 where a=t1.a and b=t1.b)
    要是 先执行where a=t1.a and b=t1.b的话a=t1.a and b=t1.b那么这个  t1 表的 别名 t1 是 怎么获得 的。
      

  4.   

    where a=t1.a and b=t1.b里的 a=t1.a and b=t1.b 是 依靠 外面的查询,还是怎么回事?晕了!!
      

  5.   

    象这样的问题不要管什么依靠不依靠,针对select一条主线就是:条件1-结果1-条件2-结果2.....-最终结果 一直往前推就行了
      

  6.   

    我知道你的意思了,a=t1.a and b=t1.b
    那么这个  t1 表的 别名 t1 是 怎么获得 的。其实这里的t1.a,t1.b并不是上一级的表,而是嵌套里的表,像
    Select * from t1 t1  where c in(Select max(c) from t1 t2 where a=t1.a and b=t1.b)
    如果在嵌套查询中真要 t1 t1,那应该是这样的
    Select * from t1 t1  where c in(Select max(c) from t1 t1,t1 t2 where a=t1.a and b=t1.b)
      

  7.   

    我觉得先执行外部的select,将所有记录的结果存到缓存中,然后执行内部的select,用外部的结果与内部的select进行条件查询,再返回结果集。然后外部的存到缓存中结果集再来匹配,符合的话就返回该行
      

  8.   

    麻烦讲解一下, 写 SQL 写进 死胡同了这两句的区别?(除结果不同外)
    其实下一级是不能用上一级的表的。
    那么 
     a=t.a and b=t.b 用的 不就是 外面的 from tb t 吗?select t.* from tb t where c in(select max(c) from tb where a=t.a and b=t.b)select t.* from tb t where c in(select max(c) from tb where a=tb.a and b=tb.b)
      

  9.   

    表结构create table t1(a int null,
    b int null,
    c int null,
    )
      

  10.   

    你写的这两句不具代表性 :
    在select t.* from tb t where c in(select max(c) from tb where a=t.a and b=t.b)中:
    a=t.a and b=t.b 这一句中 a是tb中字段,t.a也是tb中字段 t是tb表的别名 就像人的姓名中有大号和小号一样,都是一个人.
    '其实下一级是不能用上一级的表的' 这一句话应该不成立;
    如果我这样的话:改成tb1一样可以通过
    select t.* from tb1 t where c in(select max(c) from tb where a=t.a and b=t.b)再有就是你的第二条:
    select t.* from tb t where c in(select max(c) from tb where a=tb.a and b=tb.b)中
    select max(c) from tb where a=tb.a and b=tb.b 后面的条件有什么意义?
      

  11.   

    晕了。 我主要想
    知道 关联子查询里 是怎么检索数据的
    Select * from tb t1 where c in(Select max(c) from tb where a=t1.a and b=tb.b)
      

  12.   

    Select * from tb t1 看成是游标,逐条执行,每扫描一条记录,就去检查条件是否满足,满足条件则返回此条记录,否则丢弃此条记录
      

  13.   

    Select * from tb t1 where c in(Select max(c) from tb where a=t1.a and b=tb.b)那这条语句就是这样了先执行 from tb t1 , 再 执行 Where 后 部分 in 里面的  from tb   再 用 外面的 t1.a 与 里面的 a 进行 比较最后返回  最外面的  Select * 
    是这样吗
      

  14.   

    先执行Select max(c) from t1 where a=t1.a and b=t1.b 生成一个临时表tb;
    然后执行select * from t1 where c in tb;
      

  15.   

    按照 njz168(飞龙在天)  的理论
    如果这样呢?
    Select * from t1 t1 where c in(Select max(c) from tb where a=t1.a and b=tb.b)
    先执行
    Select max(c) from tb where a=t1.a and b=tb.bt1.a 里的 t1 是从哪来的??