解决方案 »

  1.   

    当取得val最大值时,count(*) 是0 ,1>0 不是刚好满足吗
      

  2.   

    当 a.val 为最大值时
    val > a.val 不成立,(select count(*) from test where name = a.name and val > a.val ) 返回 0 (没有符合条件的记录)
    1 > (select count(*) from test where name = a.name and val > a.val )
    成立,该条记录被选出其实你已经知道了,只是没绕过弯子来
    select a.* from test a where 1 > count
    count 是所有大于 a.val 的记录数,只在不存在的时候才会有 conut 等于 0.表达式 1 > 0 成立
      

  3.   

    感谢两位版主解答! 
    有些明白了,但是还有点不解,当 select a.* from test a where 2 > 0 就取了2条 我想知道这数据是怎么得出来的呢,是跟自身进行比较得出的吗? 因为我直接写select a.* from test a where 1>0这个条件是可以把所有数据都取出来的。
      

  4.   

    意思就是遍历test 表中每一条记录,然后与自身做比较,每遍历一条记录,都与自身所有记录都比较一次。相当于php中的两次foreach 
    foreach($ar as $v)
        foreach($ar as $vl)
      

  5.   

    select max(a.val) as max_val from test  group by name