读书人

新手求sql query,该如何解决

发布时间: 2012-03-16 16:34:56 作者: rapoo

新手求sql query
一个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 不存在

本人初学,还望高手们多多指点



[解决办法]
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)

读书人网 >Mysql

热点推荐