首页 > 代码库 > SQL - 查询某一字段值相同而另一字段值最大的记录

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 aWHERE 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) bWHERE a.app_name = b.app_nameAND a.app_version = b.app_versionORDER 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) bON a.app_name = b.app_nameAND a.app_version = b.app_versionORDER BY a.app_name;

 

SQL - 查询某一字段值相同而另一字段值最大的记录