【发布时间】:2010-11-03 17:29:44
【问题描述】:
我在 SQL 2000 数据库中有以下简化的表结构:
ID AppName Key Value EffectiveDate
-- ------- ----- ------- -------------
1 App1 One Past 1/1/1900
2 App1 One Present 1/1/2010
3 App1 One Future 1/1/9999
4 App1 Two Past 1/1/1900
5 App1 Two Present 1/1/2010
6 App1 Two Future 1/1/9999
7 App2 One Present 1/1/2010
8 App2 Two Present 1/1/2010
我需要能够提出问题:
给定一个特定的AppName,显示所有只有最近的键/值对,其EffectiveDate <= GetDate()
因此,如果我使用 AppName = 'App1' 调用我的神秘查询,那么我的结果将是:
ID AppName Key Value EffectiveDate
-- ------- ----- ------- -------------
2 App1 One Present 1/1/2010
5 App1 Two Present 1/1/2010
编辑:
值可以是任何东西。 ('Past','Present','Future') 仅用于使示例更清晰。他们很可能是 (45,'Bob','%$#%@#$')。
【问题讨论】:
-
感谢您告诉我们,但这是一个问答网站。你有问题吗?
-
显示的示例结果与所述条件不匹配 - “过去”和“当前”记录都具有 EffectiveDate
-
好的,所以我意识到我的问题措辞不当。我曾希望我的例子很清楚。 @Mark - 把它放在头上,因为我只想要组中时间戳最高的那些记录。结果集中不应有任何键重复。
标签: sql tsql sql-server-2000