2013-03-26 59 views
2

嗨我想將一些訪問SQL查詢轉換爲MySQL查詢,並讓它一個凹凸,因爲我不確定如何轉換這些代碼。有人請幫忙。轉換訪問SQL到MySQL

1.

SELECT Notices.Promoter, 
Sum(IIf([Notices].[Notice Type]='GRANT PERMIT' Or [Notices].[Notice Type]='GRANT VARIATION' Or [Notices].[Notice Type]='GRANT PAA',1,0)) AS Granted, 
Sum(IIf([Notices].[Notice Type]='REFUSE APPLICATION',1,0)) AS Refused, 
Sum(IIf([Notices].[Permit Status]='Deemed',1,0)) AS Deemed 
FROM Notices 
GROUP BY Notices.Promoter; 

2.

SELECT [Notices].Promoter, 
Sum(IIf([Notices].[Notice Type]='VARIATION',1,0)) AS Variation, 
Sum(IIf([Notices].[Notice Type]='TWO HOURS AFTER',1,0)) AS [Two Hours After], 
Sum(IIf([Notices].[Notice Type]='THREE MONTHS',1,0)) AS [Three Months], 
Sum(IIf([Notices].[Notice Type]='THREE DAY',1,0)) AS [Three Day], 
Sum(IIf([Notices].[Notice Type]='TEN DAY',1,0)) AS [Ten Day] 
FROM Notices 
GROUP BY [Notices].Promoter; 

Access數據庫和MySQL數據庫中標記相同我只需要在覆蓋這兩個讓我有同樣的結果。

回答

2

訪問逃逸關鍵字使用[],但使用的MySQL``,MySQL的可以使用CASE替換I如果。

SELECT `Notices`.Promoter, 
Sum(CASE WHEN `Notices`.`Notice Type`=`VARIATION` THEN 1 ELSE 0 END) AS Variation, 
Sum(CASE WHEN `Notices`.`Notice Type`='TWO HOURS AFTER' THEN 1 ELSE 0 END) AS `Two Hours After`, 
Sum(CASE WHEN `Notices`.`Notice Type`='THREE MONTHS' THEN 1 ELSE 0 END) AS `Three Months`, 
Sum(CASE WHEN `Notices`.`Notice Type`='THREE DAY' THEN 1 ELSE 0 END) AS `Three Day`, 
Sum(CASE WHEN `Notices`.`Notice Type`='TEN DAY' THEN 1 ELSE 0 END) AS `Ten Day` 
FROM Notices 
GROUP BY `Notices`.Promoter;