Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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
Access SQL-多个日期匹配的位置_Sql_Date_Ms Access_Match - Fatal编程技术网

Access SQL-多个日期匹配的位置

Access SQL-多个日期匹配的位置,sql,date,ms-access,match,Sql,Date,Ms Access,Match,我有以下名为“产品”的访问表 REF DATE DAYS 12345 26/03/2020 55 12345 26/03/2020 55 12345 20/03/2020 50 12345 30/06/2020 100 98765 05/02/2020 70 98765 05/02/2020

我有以下名为“产品”的访问表

REF         DATE               DAYS
12345       26/03/2020         55
12345       26/03/2020         55
12345       20/03/2020         50
12345       30/06/2020        100
98765       05/02/2020         70
98765       05/02/2020         70
98765       10/04/2020         91

我需要在Access中创建一个SQL查询,该查询提供一个输出,其中列出了每个唯一的REF,然后是一个YES/NO列。如果在MS Access中,所有日期值都是天的记录的相同日期,则结果为是,您可以使用聚合来计算标志,然后使用联接:

编辑:

如果希望每个ref有一行,则更容易:

select ref,   
       iif(min(date) = max(date), "Yes", "No") as same_date
from products
where days <= 90
group by ref;

嗨,Gordon,尝试过这个,但是它返回的是每一条记录,而不是每一个引用的唯一记录。而且每个“标志”都是肯定的。我注意到你的p2.days@markthornton90。我添加了每个引用一行的版本。
select p.*, nz(flag, 'NO')
from products as p left join
     (select pp.ref, 'YES' as flag
      from products as pp
      where p2.days <= 90
      group by pp.ref
      having min(date) = max(date)
     ) as pp
     on pp.ref = p.ref;
select ref,   
       iif(min(date) = max(date), "Yes", "No") as same_date
from products
where days <= 90
group by ref;