【问题标题】:Leave out certain dates on Access report在访问报告中省略某些日期
【发布时间】:2014-04-11 18:29:20
【问题描述】:

我在 Access 2013 中有一份打印设备日志的报告。每件设备都列出了一堆日期。我只想打印每件设备的最新日期。我已经搜索了互联网和这个网站,但没有运气。因此,任何建议将不胜感激。 我的 SQL 语句是: SELECT dbo_eq_location_transfer_d.equipment_id,dbo_equipment.description,dbo_eq_location_transfer_d.transaction_no,dbo_eq_location_transfer_d.job_no,dbo_jobs.description,dbo_eq_location_transfer_d.date_booked,dbo_eq_location_transfer_d.delivery_time,dbo_eq_location_transfer_d.line_no,dbo_eq_location_transfer_d.row_modified_by,dbo_eq_location_transfer_d.comment FROM (dbo_eq_location_transfer_d 内部联接 dbo_jobs ON dbo_eq_location_transfer_d.job_no = dbo_jobs.job_no) 内部联接 dbo_equipment ON dbo_eq_location_transfer_d.equipment_no = dbo_equipment.equipment_no ORDER BY dbo_eq_location_transfer_d.equipment_id, dbo_eq_location_transfer_d.transaction_no;

date_booked 字段是我试图缩小范围的日期字段。我有一个有效的简单 SQL 查询,我一直在尝试将其复制到 about SQL 中,但似乎无法使其网格化。这是: 选择 [dbo_eq_location_transfer_d.equipment_no],Max(dbo_eq_location_transfer_d.date_booked) AS [“最新日期”] FROM dbo_eq_location_transfer_d GROUP BY [dbo_eq_location_transfer_d.equipment_no];

【问题讨论】:

  • 您能否进行访问GROUP BY 查询,为您提供每件设备的Max() 日期?
  • 我已经尝试过了,但我似乎找不到在哪里这样做?
  • 嗯,需要确定的问题...您的意思是您只想要该设备的一行并且它应该显示最近的日期?还是您的意思是要打印该设备的所有行,但只打印最新日期?
  • 我只想为设备打印一行,它应该显示最近的日期。

标签: ms-access vba


【解决方案1】:

在您的查询中,将日期字段条件设置为:

>Now()-30

这将显示过去 30 天的任何日期,只需将 30 更改为您想要查看的天数。

【讨论】:

  • 如果日期很新,但我有一些几个月没有任何活动。我们可以调整日期答案以仅采用最新日期吗?
【解决方案2】:

现在我了解了您的结构和数据,这就是我所做的: (1) 创建以下查询,为每个 'equipment_no' 选择最近的 'date_booked';保存名为“23020071_A”的查询:

SELECT dbo_eq_location_transfer_d.equipment_no, 
First(dbo_eq_location_transfer_d.transaction_no) AS FirstOftransaction_no, 
First(dbo_eq_location_transfer_d.job_no) AS FirstOfjob_no, 
First(dbo_eq_location_transfer_d.date_booked) AS FirstOfdate_booked
FROM (dbo_eq_location_transfer_d 
INNER JOIN dbo_jobs ON dbo_eq_location_transfer_d.job_no = dbo_jobs.job_no) 
INNER JOIN dbo_equipment ON dbo_eq_location_transfer_d.equipment_no = dbo_equipment.equipment_no
GROUP BY dbo_eq_location_transfer_d.equipment_no
ORDER BY First(dbo_eq_location_transfer_d.date_booked) DESC;

(2) 我创建了以下查询,将新查询与您现有的查询相结合:

SELECT dbo_eq_location_transfer_d.equipment_id, dbo_equipment.description, 
dbo_eq_location_transfer_d.transaction_no, dbo_eq_location_transfer_d.job_no,
dbo_jobs.description, dbo_eq_location_transfer_d.date_booked, 
dbo_eq_location_transfer_d.delivery_time, dbo_eq_location_transfer_d.line_no, 
dbo_eq_location_transfer_d.row_modified_by, dbo_eq_location_transfer_d.comment
FROM 23020071_A INNER JOIN ((dbo_eq_location_transfer_d 
INNER JOIN dbo_jobs ON dbo_eq_location_transfer_d.job_no = dbo_jobs.job_no) 
INNER JOIN dbo_equipment ON dbo_eq_location_transfer_d.equipment_no = dbo_equipment.equipment_no) 
ON ([23020071_A].FirstOftransaction_no = dbo_eq_location_transfer_d.transaction_no) 
AND ([23020071_A].equipment_no = dbo_eq_location_transfer_d.equipment_no) 
AND ([23020071_A].FirstOfjob_no = dbo_eq_location_transfer_d.job_no)
ORDER BY dbo_eq_location_transfer_d.equipment_id, dbo_eq_location_transfer_d.transaction_no;

现在,当我运行第二个查询时,它只返回该设备的最新行。

【讨论】:

  • 我正在使用查询,但我一定做错了,因为我无法让 Max 关键字起作用。有什么方法可以做你的建议吗?谢谢。
  • 好的,应该是星期五。如何更新我的问题?谢谢。
  • 好吧,我试过了,但它没有用,但我正在根据您的建议一次重新创建一列查询,它似乎正在工作。所以原来的SQL一定有它不喜欢的地方。
  • 好吧,显然它不喜欢所有字段上的“分组依据”,因为在我添加“事务号”字段的那一刻,它就停止工作了。所以我想我会一直坚持下去,直到我让它工作为止。
  • 这是一个日期字段。没有不寻常的属性。
猜你喜欢
  • 2010-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-20
  • 1970-01-01
  • 2017-08-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多