1

我正在尝试构建每日报告,目前我使用的代码有效,但不是我需要它做的事情。

SELECT Notices.Promoter, 
Sum(IIf([Notices].[Type]='GRANT PERMIT' Or [Notices].[Type]='GRANT VARIATION' Or [Notices].[Notice Type]='GRANT PAA',1,0)) AS Granted, 
Sum(IIf([Notices].[Type]='REFUSE    APPLICATION',1,0)) AS Refused, 
Sum(IIf([Notices].[Status]='Deemed',1,0)) AS Deemed, 
Sum(IIf([Notices].[Error]<>"" And Notices.[Category]<>"Observation" And Notices.[Category]<>"S.74 Overrun",1,0)) AS [Potential Penalty]
FROM Notices
WHERE (((Notices.[Day Of Week])=[TempVars]![DayReport]))
GROUP BY Notices.Promoter;

tempVar [DayReport] 是星期几 mon,tue,wed.... sun,代码输出这个

Promoter | Granted | Refused | Deemed | Potential Penalty
Name     |   0     |    0    |    0   |   0
Name2    |   3     |    0    |    0   |   0
Name3    |   4     |    2    |    1   |   0
Name4    |   0     |    1    |    1   |   0
Name5    |   1     |    0    |    0   |   0

我想要的是不显示在这样的字段中全为 0 的发起人

Promoter | Granted | Refused | Deemed | Potential Penalty
Name2    |   3     |    0    |    0   |   0
Name3    |   4     |    2    |    1   |   0
Name4    |   0     |    1    |    1   |   0
Name5    |   1     |    0    |    0   |   0

由于我不确定如何去做,我想我会把它交给 Stackoverflow 的优秀人士

4

1 回答 1

0

SELECT  *
FROM
(
    SELECT  Notices.Promoter, 
            Sum(IIf([Notices].[Type]='GRANT PERMIT' Or [Notices].[Type]='GRANT VARIATION' Or [Notices].[Notice Type]='GRANT PAA',1,0)) AS Granted, 
            Sum(IIf([Notices].[Type]='REFUSE    APPLICATION',1,0)) AS Refused, 
            Sum(IIf([Notices].[Status]='Deemed',1,0)) AS Deemed, 
            Sum(IIf([Notices].[Error]<>"" And Notices.[Category]<>"Observation" And Notices.[Category]<>"S.74 Overrun",1,0)) AS [Potential Penalty]
    FROM    Notices
    WHERE   (((Notices.[Day Of Week])=[TempVars]![DayReport]))
    GROUP   BY Notices.Promoter
) s
WHERE   Promoter <> 0
        Refused <> 0 AND 
        Deemed <> 0 AND 
        [Potential Penalty] <> 0

更新 1

SELECT  Notices.Promoter, 
        Sum(IIf([Notices].[Type]='GRANT PERMIT' Or [Notices].[Type]='GRANT VARIATION' Or [Notices].[Notice Type]='GRANT PAA',1,0)) AS Granted, 
        Sum(IIf([Notices].[Type]='REFUSE    APPLICATION',1,0)) AS Refused, 
        Sum(IIf([Notices].[Status]='Deemed',1,0)) AS Deemed, 
        Sum(IIf([Notices].[Error]<>"" And Notices.[Category]<>"Observation" And Notices.[Category]<>"S.74 Overrun",1,0)) AS [Potential Penalty]
FROM    Notices
WHERE   (((Notices.[Day Of Week])=[TempVars]![DayReport]))
GROUP   BY Notices.Promoter
HAVING  Sum(IIf([Notices].[Type]='GRANT PERMIT' Or [Notices].[Type]='GRANT VARIATION' Or [Notices].[Notice Type]='GRANT PAA',1,0)) <> 0 AND
        Sum(IIf([Notices].[Type]='REFUSE    APPLICATION',1,0)) <> 0 AND
        Sum(IIf([Notices].[Status]='Deemed',1,0)) <> 0 AND
        Sum(IIf([Notices].[Error]<>"" And Notices.[Category]<>"Observation" And Notices.[Category]<>"S.74 Overrun",1,0)) <> 0
于 2013-03-06T13:04:30.060 回答