2013-03-06 109 views
1

即時通訊我試圖建立按日報告在此刻的代碼即時通訊使用的作品,但不是我需要它做的。訪問2007 SQL查詢忽略0值

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 

由於林不知道如何去這個問題,我想我會把它#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 
+0

這並沒有爲我工作,說'語法錯誤在FROM Clause'。 – MasterT 2013-03-06 13:13:15

+0

看到我的更新,我不知道是否支持別名,因爲在MySQL中,它會。 – 2013-03-06 13:15:32

+0

現在沒有收回任何東西。 – MasterT 2013-03-06 13:28:22