设有表one,其字段两个:colx 和 coly。
Table one的数据如下colx |coly
1 3
2 3
3 3
4 10
5 10
6 9想取到所有为最大值的coly的colx的数据。
在表中,最大的coly是10,想取到这两条colx的数据。现在我的方法是
SELECT colx
FROM one
WHERE
coly =
(SELECT MAX(coly) FROM one)请问还有效率更高的办法吗?
请指教,谢谢!!
sql优化
Table one的数据如下colx |coly
1 3
2 3
3 3
4 10
5 10
6 9想取到所有为最大值的coly的colx的数据。
在表中,最大的coly是10,想取到这两条colx的数据。现在我的方法是
SELECT colx
FROM one
WHERE
coly =
(SELECT MAX(coly) FROM one)请问还有效率更高的办法吗?
请指教,谢谢!!
sql优化
from one t
where not exists (select 1 from one where coly>t.coly)
where not exists (select 1 from one where A.coly<coly)