2013-04-20 14 views
5

Ben Erişim çevirdimBu SQL sorgusunu MS Access sorgusuna nasıl dönüştürebilirim?

SELECT  COUNT(DISTINCT dbo.Polling_Stations.P_ID) AS [Male Stations] 
FROM   dbo.Agent INNER JOIN 
        dbo.Polling_Stations ON dbo.Agent.P_ID = dbo.Polling_Stations.P_ID 
GROUP BY dbo.Polling_Stations.Gender 
HAVING  (dbo.Polling_Stations.Gender = N'Male') 

SQL'de sorgusu vardır:

SELECT  COUNT(DISTINCT Polling_Stations.P_ID) AS [Male Stations] 
FROM   Agent INNER JOIN 
        Polling_Stations ON Agent.P_ID = Polling_Stations.P_ID 
GROUP BY Polling_Stations.Gender 
HAVING  (Polling_Stations.Gender = 'Male') 

Ama bu bana bir hata veriyor: DISTINCT sözdizimi hatası Kont' sorgu ifadesinde (Operatör eksik) (Polling_Stations.P_ID)'.

+0

senin söz dizimi hatası nedir yapmanız gerekir? – Kermit

+1

'Count (DISTINCT Polling_Stations.P_ID)' deyimindeki sözdizimi hatası (işleç eksik). – sangeen

+0

Köşeli parantezler erişimde geçerli mi? –

cevap

5

Erişim SQL COUNT(DISTINCT ...) desteklemez, bu nedenle bunun yerine

SELECT COUNT(*) AS [Male Stations] 
FROM 
(
    SELECT DISTINCT Polling_Stations.P_ID 
    FROM Agent INNER JOIN Polling_Stations 
     ON Agent.P_ID = Polling_Stations.P_ID 
    WHERE Polling_Stations.Gender = "Male" 
) 
4

Erişim, Count(DISTINCT ...) desteklemiyor. Alt sorguda SELECT DISTINCT ve üst sorgudan sayımı yapın.

SELECT COUNT(ps.P_ID) AS [Male Stations] 
FROM 
    Agent 
    INNER JOIN 
    (
     SELECT DISTINCT P_ID 
     FROM Polling_Stations 
     WHERE Gender = 'Male' 
    ) AS ps 
    ON Agent.P_ID = ps.P_ID;