我有一个像下面这样的表,每年有一个空值。我需要在Access查询中计算每个Id的连续最大计数。我在VBA方面不擅长,所以试图在Access查询中完成它。
ID 2001 2002 2004 2005 2006 2007
101 1 1 1 1
102 1 1 1 1 1
103 1
104 1 1 1 1 1
105 1 1 1 1 1 1
106 1 1 1
答案 0 :(得分:0)
可能,但不确定“最大数量”可能意味着什么:
Select
ID,
Nz([2001],0)+Nz([2002],0)+Nz([2003],0)+Nz([2004],0)+Nz([2005],0)+Nz([2006],0)+Nz([2007],0) As YearCount
From
YourTable
连续三年:
Select
ID,
([2001]+[2002]+[2003] Is Not Null) Or
([2002]+[2003]+[2004] Is Not Null) Or
([2003]+[2004]+[2005] Is Not Null) Or
([2004]+[2005]+[2006] Is Not Null) Or
([2005]+[2006]+[2007] Is Not Null) As Count3
From
YourTable
和/或:
Select
ID,
([2001]+[2002]+[2003] Is Not Null) As [2001-2003],
([2002]+[2003]+[2004] Is Not Null) As [2002-2004],
([2003]+[2004]+[2005] Is Not Null) As [2003-2005],
([2004]+[2005]+[2006] Is Not Null) As [2004-2006],
([2005]+[2006]+[2007] Is Not Null) As [2005-2007]
From
YourTable