1

我有以下功能查询来在 Access 中创建交叉表/数据透视表

TRANSFORM Sum(y.TNAV) AS TNAV
SELECT y.RecDate
FROM BNYDaily AS y
WHERE (((y.AccName) In ("A","B")) AND y.RecDate >= DateValue("1/1/2013"))
GROUP BY y.RecDate
PIVOT y.AccName; ) 

问题是查询返回的结果包含NULL混淆了我的计算的字段。我想省略此交叉表中NULL在任一列中具有值的行:

RecDate     A                   B
....
1/25/2013   1,469,004,032.00    968.63
1/26/2013   1,466,082,304.00    
1/28/2013                       973.91
1/29/2013   1,471,277,440.00    971.66
...

我尝试了以下查询,该查询将上述查询用作子查询,但没有任何运气:

SELECT * FROM
(
TRANSFORM Sum(y.TNAV) AS TNAV
SELECT y.RecDate
FROM BNYDaily AS y
WHERE (((y.AccName) In ("A","B")) AND y.RecDate >= DateValue("1/1/2013"))
GROUP BY y.RecDate
PIVOT y.AccName; 
) AS t
WHERE t.A IS NOT NULL AND t.B is NOT NULL

奇怪的是,它不在 Access 中运行并返回错误。如果我从交叉表查询作为保存的查询表进行查询,它可以工作。有任何想法吗?

4

1 回答 1

2

与其从交叉表的结果中“挤出”包含 Null 的行,不如从交叉表的中消除产生 Null 的行怎么样?我刚刚尝试了以下方法,它似乎有效:

TRANSFORM Sum(y.TNAV) AS TNAV
SELECT y.RecDate
FROM 
    (
        SELECT RecDate, AccName, TNAV
        FROM BNYDaily 
        WHERE RecDate IN (SELECT RecDate FROM BNYDaily WHERE AccName = "A")
            AND RecDate IN (SELECT RecDate FROM BNYDaily WHERE AccName = "B")
    ) AS y
WHERE (((y.AccName) In ("A","B")) AND y.RecDate >= DateValue("1/1/2013"))
GROUP BY y.RecDate
PIVOT y.AccName;
于 2013-10-24T16:13:14.273 回答