ms访问计数不同的列

时间:2013-02-09 06:33:57

标签: sql ms-access count distinct

以下代码给出了计数不同值的语法错误。

SELECT SUM(house_thanas.target)               AS target, 
       SUM(reports_db.ach_total)              AS Total, 
       Count(DISTINCT reports_db.report_date) AS WorkingDays 
FROM   ((areas 
         INNER JOIN distribution_houses 
                 ON areas.area_id = distribution_houses.area_id) 
        INNER JOIN house_thanas 
                ON distribution_houses.distribution_house_id = 
                   house_thanas.distribution_house_id) 
       INNER JOIN reports_db 
               ON house_thanas.thana_id = reports_db.thanaid 
WHERE  reports_db.report_date BETWEEN 
       #2012/02/10 12:00:00 am# AND #2013/02/09 11:59:59 pm# 

如何在microsoft access数据库中查找不同的计数值?

1 个答案:

答案 0 :(得分:0)

我认为你没有看到建议的内容,即:

 SELECT SUM(house_thanas.target)               AS target, 
   SUM(reports_db.ach_total)              AS Total, 
   (SELECT Count(*) As JustOnce
    FROM (SELECT DISTINCT report_date FROM reports_db)) AS WorkingDays 

 <...>

在查询设计窗口的设计视图中,子查询应设置为Expression。