san*_*een 5 sql ms-access distinct
我在SQL中有Query
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')
Run Code Online (Sandbox Code Playgroud)
我已将其转换为Access为:
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')
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误:查询表达式'Count(DISTINCT Polling_Stations.P_ID)'中的语法错误(缺少运算符).
Access SQL不支持COUNT(DISTINCT ...),因此您需要这样做
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"
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
901 次 |
| 最近记录: |