[英]SQL Max(date) without group by
I have the following table...我有下表...
MemberID ServDate
001 12-12-2015
001 12-13-2015
001 12-15-2015
002 11-30-2015
002 12-04-2015
And I want to make it look like this...我想让它看起来像这样......
MemberID ServDate LastServDate
001 12-12-2015 12-15-2015
001 12-13-2015 12-15-2015
001 12-15-2015 12-15-2015
002 11-30-2015 12-04-2015
002 12-04-2015 12-04-2015
Is there a way I can do this without having to use a GROUP BY
or nested query?有没有一种方法可以做到这一点而不必使用
GROUP BY
或嵌套查询? (I'm dealing with a very large database and the GROUP BY slows things down considerably) (我正在处理一个非常大的数据库,而 GROUP BY 大大减慢了速度)
SELECT
MemberID, ServDate,
MAX(ServDate) OVER (PARTITION BY MemberID) AS LastServDate
FROM Table
Standard SQL, so works in most modern RDBMS (including SQL Server and Oracle).标准 SQL,因此适用于大多数现代 RDBMS(包括 SQL Server 和 Oracle)。
EDIT by the way, if you want to learn more: MSDN ref.顺便说一下,如果您想了解更多信息,请编辑: MSDN ref。 for OVER
结束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.