问题描述
在AIX上的DB2上,我试图根据其EffectiveDate检索每个
唯一代码的最新ID。例如,在下面的数据
中,我想检索ID BE0191026,因为它具有最新的
EffectiveDate,1/1/2001,用于代码的记录PG2SS0。可以
有人建议适当的方法来获取所需的SQL查询吗?
谢谢,Jim D.
代码ID EffectiveDate
103631 BE010662E 8/1/2003
103631 BE010662E 8/1/2003
10004X BE0106Y50 8/1/2003
QJD BE0189010 9/27/1999
QJD BE0189010 7/15/2002
PG2SS0 BE0191002 12/1/1996
PG2SS0 BE0191002 5 / 1/2000
PG2SS0 BE0191002 12/1/1996
PG2SS0 BE0191002 5/1/2000
PG2SS0 BE0191026 1/1/2001
PG2SS0 BE0191008 12/1/1996
PG2SS0 BE0191008 5/1/2000
AR02 1/1/1992
P2F BE0116020 11/8/1995
P3F BE0116020 11/8/1995
On DB2 on AIX, I''m attempting to retrieve the most recent ID for each
unique Code based on its EffectiveDate. For example, in the data
below, I want to retrieve ID BE0191026 as it has the most recent
EffectiveDate, 1/1/2001, for the records with the Code PG2SS0. Can
anyone suggest an appropriate approach for the required SQL query?
Thanks, Jim D.
Code ID EffectiveDate
103631BE010662E 8/1/2003
103631BE010662E 8/1/2003
10004XBE0106Y50 8/1/2003
QJD BE0189010 9/27/1999
QJD BE0189010 7/15/2002
PG2SS0BE019100212/1/1996
PG2SS0BE0191002 5/1/2000
PG2SS0BE019100212/1/1996
PG2SS0BE0191002 5/1/2000
PG2SS0BE0191026 1/1/2001
PG2SS0BE019100812/1/1996
PG2SS0BE0191008 5/1/2000
AR02 1/1/1992
P2F BE011602011/8/1995
P3F BE011602011/8/1995
推荐答案
EffectiveDate是字符串还是SQL-Date?当SQL Dateselect * from
table where CODE =''PGSS0''order by EffectiveDate desc fetch first row
只优化1行
如果EffectiveDate是一个字符串,你需要一个函数来构建一个yyyymmdd
字符串进行排序。
Bernd
Is EffectiveDate a string or a SQL-Date? When SQL Date "select * from
table where CODE=''PGSS0'' order by EffectiveDate desc fetch first row
only optimize for 1 row"
If EffectiveDate is a string you need a function which builds a yyyymmdd
string for sorting.
Bernd
这篇关于检索最新的条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!