本文介绍了使用 SQL 获取不同的最大日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不太确定如何为我的问题命名,但这就是我想要做的:
I'm not sure quite how to title my question but this is what I'm trying to do:
给定 pc_tmppl_tbl
Given pc_tmppl_tbl
pc_tmppl_attach pc_tmppl_val1 pc_tmppl_crtdt
AJC05-06 AJCINT 2005-08-15 10:32:03.790
AJC06-07 AJCINT 2006-10-17 10:02:06.570
AJC07-08 AJCINT 2007-06-13 10:44:53.573
AJC08-09 AJCINT 2008-06-27 09:51:17.290
AJC09-10 AJCINT 2009-07-20 14:26:06.270
AJC10-11 AJCINT 2010-08-26 11:54:32.777
AJC99-001 AJCINT 2005-05-30 19:30:51.623
ALPI05-06 ALPINE 2005-05-30 19:30:51.623
ALPI07-08 ALPINE 2006-12-11 13:57:09.923
ALPI07-08 ALPINE 2007-05-24 14:04:07.867
ALPI08-09 ALPINE 2008-04-30 09:49:24.140
我希望它返回 pc_tmppl_crtdt 及其相应的 pc_tmppl_attach 的最大日期
I want it to return the max date for pc_tmppl_crtdt and its corresponding pc_tmppl_attach so
ALPI08-09 ALPINE 2008-04-30 09:49:24.140
AJC10-11 AJCINT 2010-08-26 11:54:32.777
我一直在尝试子查询,但还没有完全找到答案,任何帮助将不胜感激.
I've been trying sub queries but haven't quite hit on the answer, any help would be much appreciated.
推荐答案
Select T.pc_tmppl_attach, T.pc_tmppl_val1, T.pc_tmppl_crtdt
From pc_temppl_tbl As T
Join (
Select pc_tmppl_val1, Max( T1.pc_tmppl_crtdt ) As MaxDateTime
From pc_temppl_tbl As T1
Group By T1.pc_tmppl_val1
) As Z
On Z.pc_tmppl_val1 = T.pc_tmppl_val1
And Z.MaxDateTime = T.pc_tmppl_crtdt
这篇关于使用 SQL 获取不同的最大日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!