[英]MS Access SQL Date Calculation with Single Date
I have two tables linked to a MS Access database I have created. 我有两个表链接到我创建的MS Access数据库。 One of my tables contains many rows of data and has one field with a date in there.
我的一张表包含多行数据,并且其中一个字段带有日期。 My second table has one single field and one single entry, which is the date.
我的第二张表只有一个字段和一个条目,即日期。
My second table at the moment has a field called "ReportDate" and then the content is "2019-03-04". 我目前的第二张表中有一个名为“ ReportDate”的字段,然后内容为“ 2019-03-04”。
I am trying to create a query to perform the difference between the dates in the first table and the single date in the second table. 我试图创建一个查询以执行第一个表中的日期和第二个表中的单个日期之间的差异。
Table 1 表格1
ID Location Date
1 US 2019-05-10
2 US 2019-06-15
3 CA 2019-05-23
4 CA 2019-06-04
5 US 2019-10-20
Table 2 表2
ReportDate
2019-03-05
RESULT 结果
ID Location Date DayDiff
1 US 2019-05-10 66
2 US 2019-06-15 102
3 CA 2019-05-23 79
4 CA 2019-06-04 91
5 US 2019-10-20 229
Any help would be greatly appreciated! 任何帮助将不胜感激!
I tried DateDiff("d",Table2.ReportDate,Table1.Date), but realized that I have nothing joining the 2 tables together. 我尝试使用DateDiff(“ d”,Table2.ReportDate,Table1.Date),但意识到我没有任何东西可以将2个表连接在一起。 Any guidance would be greatly appreciated!
任何指导将不胜感激!
You can use a cross join
, which in MS Access is done with a comma: 您可以使用
cross join
,该联接在MS Access中用逗号完成:
select t1.*, t2.ReportDate,
DateDiff("d", t2.ReportDate, t1.Date)
from table1 as t1,
table2 as t2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.