我正在尝试编写一个 Access 查询,该查询将单个表连接两次,然后对每个表的一个字段进行计数。
SELECT Wines.wID,
Wines.num,
Wines.Brand,
Wines.wYear,
Wines.Variety,
Wines.Score,
g.fName,
g.lName ,
Count(DISTINCT Votes.vote1) AS Vote1,
Count(DISTINCT Votes_1.vote2) AS Vote2
FROM ((Wines
LEFT JOIN Guests AS g
ON Wines.wID = g.wineID)
LEFT JOIN Votes
ON Wines.num = Votes.vote1)
LEFT JOIN Votes AS Votes_1
ON Wines.num = Votes_1.vote2
WHERE (((Wines.pID)=2))
GROUP BY Wines.wID, Wines.num, Wines.Brand,
Wines.wYear, Wines.Variety, Wines.Score, g.fName, g.lName
ORDER BY Wines.Score DESC , Count(DISTINCT Votes.vote1) DESC;
但是,它不起作用。COUNT(DISTINCT)
似乎在 Access 中不起作用。忽略它可以让查询运行,但我没有得到正确的结果。只使用一次就可以了。我似乎无法在 COUNT 语句中编写子查询,而且我不确定还能做什么。