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] は月曜日、火曜日、水曜日....太陽であり、コードはこれを出力します

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 に答える