首页 > 代码库 > 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 - 查询某一字段值相同而另一字段值最大的记录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。