问题:列出每个职工经手的具有最高金额的订购单信息。
select * from suguanquan.订购单 a where 金额=
(select MAX(金额) from suguanquan.订购单 b where a.职工号=b.职工号)
order by 职工号 ASC
这查询方式可用嵌套查询的方式来替换么?如果有请写出替换代码。
你是想转为非相关子查询吧,这个没办法转,不过可以转化为连接
select o1.* from 订单 a1
join 订单 a2
on(a1.职工=a2.职工)
group by o1.职工
having a1.金额=max(a2.金额);
连接速度应该要比子查询快,在有索引的时候。