一个table, x, y, z 3个字段, 求y-z的最大值所对应的x值,自己写了query,不过有错误select temp.a
from      
     (select x a,abs(y-z) b
     from table t
     where z in
     (SELECT z FROM `t` WHERE z > 0)   
     group by x) temp
where temp.b in (select max(b) from temp)提示 table.temp 不存在本人初学,还望高手们多多指点

解决方案 »

  1.   

    select temp.a
    from     
        (select x a,abs(y-z) b
        from table t
        where z in
        (SELECT z FROM `t` WHERE z > 0)  
        group by x) temp
    where temp.b in (select max(b) from (select x a,abs(y-z) b
        from table t
        where z in
        (SELECT z FROM `t` WHERE z > 0)  
        group by x) temp1)
      

  2.   

    还是高手厉害
    派生表是不是只能用在from里啊?有更简洁的query吗?