我在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 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 ORDER BY dbo_eq_location_transfer_d.equipment_id,dbo_eq_location_transfer_d.transaction_no;
date_booked字段是我正在尝试缩小范围的日期字段。我有一个简单的SQL查询可以工作,我一直在尝试复制到约SQL,但似乎无法让它进行网格化。它是: SELECT [dbo_eq_location_transfer_d.equipment_no],Max(dbo_eq_location_transfer_d.date_booked)AS [“最新日期”] 来自dbo_eq_location_transfer_d GROUP BY [dbo_eq_location_transfer_d.equipment_no];
答案 0 :(得分:0)
在您的查询中,将日期字段条件设置为:
>Now()-30
这将显示过去30天的任何日期,只需将30更改为您想要查看的天数。
答案 1 :(得分:0)
现在我了解你的结构&数据,这是我做的: (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;
现在,当我运行第二个查询时,它只返回该设备的最新行。