首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

新手求sql query,该如何解决

2012-03-16 
新手求sql query一个table, x, y, z 3个字段, 求y-z的最大值所对应的x值,自己写了query,不过有错误select

新手求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)

热点排行