SQL 分组后获取分组内某一个属性值最大或者最小等等

来源:互联网 发布:mac os 下安装win8 编辑:程序博客网 时间:2024/06/13 22:38
获取某个人在同一个SourceID 下PostTime最大的记录:
自己的代码:
select A.* from  psmc_user_assembly A,(

SELECT SourceID,max(PostTime) maxpost FROM `psmc_user_assembly`  where UserID='7f261265-7606-4800-92a8-b70413ecf0cc' GROUP BY SourceID ORDER BY PostTime )B  where A.SourceID=B.SourceID and A.PostTime=b.maxpost;

参考:

http://www.2cto.com/database/201211/169178.html

http://blog.csdn.net/tatagg/article/details/43672487?locationNum=5

http://www.cnblogs.com/myjoan/p/6123304.html

http://www.tuicool.com/articles/j6vQzaI

http://blog.csdn.net/looksun/article/details/41172293


感谢上述几篇文章的作者的分享。

0 0