Microsoft Access从SQL数据库查询选择Count Distinct Issue

时间:2011-10-21 14:07:13

标签: sql database ms-access

我有一个问题:

SELECT COUNT(DISTINCT dbo_tblBidder.bidder_id) AS TotalRegistrants, 
    SUM(dbo_tblItem.item_premium + dbo_tblItem.item_pr) AS SumTotal, 
    dbo_tblBidder.bidder_type

FROM dbo_tblBidder LEFT OUTER JOIN dbo_tblItem ON 
    dbo_tblItem.item_bidder_number = dbo_tblBidder.bidder_number AND 
    dbo_tblItem.item_sale_id = dbo_tblBidder.bidder_sale_id

WHERE (dbo_tblBidder.bidder_sale_id = 235)

GROUP BY dbo_tblBidder.bidder_type

当我尝试在MS Access中执行此操作时,我被告知:

Missing oporator 'COUNT(DISTINCT dbo_tblBidder.bidder_id)'

当我点击"确定"时,它会突出显示" dbo_tblBidder"。这个查询在SQL服务器上运行得很好,我不知道MS Access认为缺少哪个oporator。任何帮助将不胜感激。

更新

我实际上必须尝试:

SELECT     Total.count, SUM(dbo_tblItem.item_premium + dbo_tblItem.item_pr) AS SumTotal, dbo_tblBidder.bidder_type
FROM         dbo_tblBidder LEFT OUTER JOIN
                  dbo_tblItem ON dbo_tblItem.item_bidder_number = dbo_tblBidder.bidder_number   AND 
                  dbo_tblItem.item_sale_id = dbo_tblBidder.bidder_sale_id LEFT OUTER JOIN
                      (SELECT     COUNT(bidder_type) AS count, bidder_type
                        FROM          dbo_tblBidder AS tblBidder_1
                        WHERE      (bidder_sale_id = 235)
                        GROUP BY bidder_type) AS Total ON dbo_tblBidder.bidder_type = Total.bidder_type
WHERE     (dbo_tblBidder.bidder_sale_id = 235)
GROUP BY dbo_tblBidder.bidder_type, Total.count
ORDER BY dbo_tblBidder.bidder_type

我正在等待那个试图运行它的人的回复,看看这对他们是否有效。

更新

这不起作用。现在,它告诉我:

  

查询表达式中的语法错误(缺少运算符)"。

然后,它突出了" mber"来自dbo_tblBidder.bidder_number,其中说:

  

dbo_tblItem ON dbo_tblItem.item_bidder_number = dbo_tblBidder.bidder_number

ANSWERED:

MS Access to SQL query issue

2 个答案:

答案 0 :(得分:1)

Access不支持COUNT Distinct。如果您需要,可以试试here

答案 1 :(得分:0)

聚合函数(Count函数)中有Distinct。删除distinct,它应该可以正常工作。

如果您仍然需要计算不同的bidder_ID,我建议您在单独的查询中提取。