SQL - 查询某一字段值相同而另一字段值最大的记录
Posted huey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL - 查询某一字段值相同而另一字段值最大的记录相关的知识,希望对你有一定的参考价值。
1.
SELECT a.* FROM app a WHERE a.app_version = (SELECT MAX(b.app_version) FROM app b WHERE b.app_name = a.app_name) ORDER BY a.app_name;
2.
SELECT a.* FROM app a WHERE NOT EXISTS(SELECT 1 FROM app b WHERE b.app_name = a.app_name AND b.app_version > a.app_version) ORDER BY a.app_name;
3.
SELECT a.* FROM app a, (SELECT app_name, MAX(app_version) AS app_version FROM app GROUP BY app_name) b WHERE a.app_name = b.app_name AND a.app_version = b.app_version ORDER BY a.app_name;
4.
SELECT a.* FROM app a INNER JOIN (SELECT app_name, MAX(app_version) AS app_version FROM app GROUP BY app_name) b ON a.app_name = b.app_name AND a.app_version = b.app_version ORDER BY a.app_name;
以上是关于SQL - 查询某一字段值相同而另一字段值最大的记录的主要内容,如果未能解决你的问题,请参考以下文章