码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-12-08 18:38:35      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:app   相同   version   sel   div   join   记录   group   sts   

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 - 查询某一字段值相同而另一字段值最大的记录

标签:app   相同   version   sel   div   join   记录   group   sts   

原文地址:http://www.cnblogs.com/huey/p/6145662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!