Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将带有大小写和时间的聚合SQL查询转换为MS Access_Sql_Ms Access_Aggregate Functions - Fatal编程技术网

将带有大小写和时间的聚合SQL查询转换为MS Access

将带有大小写和时间的聚合SQL查询转换为MS Access,sql,ms-access,aggregate-functions,Sql,Ms Access,Aggregate Functions,我在SQL中执行查询时没有问题,但在Access中不起作用 案例在访问权中不可用,因此必须使用IIf select sum(case when date between '2012-05-01' AND '2012-06-01' then value else 0 end) as sum1, sum(case when date between '2012-05-01' AND '2012-10-01' then value else 0 end) as sum2, su

我在SQL中执行查询时没有问题,但在Access中不起作用 案例在访问权中不可用,因此必须使用IIf

select
    sum(case when date between '2012-05-01' AND '2012-06-01' then value else 0 end) as sum1,
    sum(case when date between '2012-05-01' AND '2012-10-01' then value else 0 end) as sum2,
    sum(case when situation like 'Urgent' then 1 else 0 end) as urgent,
    sum(case when situation like 'Anual' then 1 else 0 end) as anual,
    sum(1) as total
from mytable
有更好的方法吗? 这个查询有效吗

  select
        sum(IIf date between '2012-05-01' AND '2012-06-01',value,0) as sum1,
        sum(IIf date between '2012-05-01' AND '2012-10-01',value,0) as sum2,
        sum(IIf situation like 'Urgent',1,0 ) as urgent,
        sum(IIf situation like 'Anual' ,1,0 ) as anual,
        sum(1) as total
    from mytable

IIf(expression,truepart,falsepart)

日期
括在方括号中,因为两者都是保留字

您的
Like
比较没有包括任何模式匹配,因此我将
=
替换为

我假设date是日期/时间数据类型,所以用
分隔符将值括起来

SELECT
    Sum(IIf([date] BETWEEN #2012-05-01# AND #2012-06-01#,[value],0)) AS Sum1,
    Sum(IIf([date] BETWEEN #2012-05-01# AND #2012-10-01#,[value],0)) AS Sum2,
    Sum(IIf(situation = 'Urgent',1,0 )) AS urgent,
    Sum(IIf(situation = 'Anual' ,1,0 )) AS anual,
    Sum(1) AS total
FROM mytable;