我需要从两个表中提取数据:Neptune_FN_Analysis
并且Neptune_prem
将有 3 个字段称为readings_miu_id
(与人名或项目 # 相当)ReadDate
,,ReadTime
(所有这些都在 中Neptune_FN_Analysis
)。有些readings_miu_id
s 有多个ReadTime
s 多天,但我只想提取readings_miu_id
每天输入的“最后一次”。
我需要所有readings_miu_id
具有所选范围的输入日期的 s,但只有ReadTime
我要提取的每条记录的最后输入日期。
到目前为止,我基于一张表的解决方案是:
SELECT readings_miu_id, Reading, ReadDate, ReadTime, MIUwindow, SN, Noise, RSSI, OriginCol, ColID, Ownage
FROM analyzed AS A
WHERE ReadDate Between #4/21/2009# and #4/29/2009#
AND ReadTime=
(SELECT TOP 1 analyzed.ReadTime FROM analyzed
where analyzed.readings_miu_id = A.readings_miu_id
AND analyzed.ReadDate = A.ReadDate
ORDER BY analyzed.ReadTime DESC);
当我尝试调整此解决方案时,我不能这样做,FROM [tableName] as A, INNER JOIN
因为它给了我一个错误。我的前任制作的原始代码(这是我正在尝试修改/修复的)如下:
SELECT readings_miu_id, Reading, ReadDate,Format([MIUtime],'hh:mm:ss') AS
ReadTime, MIUwindow, SN, Noise, RSSI, ColRSSI, MIURSSI, Firmware, CFGDate, FreqCorr,
Active, MeterType, OriginCol, ColID, Ownage, SiteID, PremID, Neptune_prem.prem_group1,
Neptune_prem.prem_group2, ReadID
INTO analyzed
FROM Neptune_FN_Analysis INNER JOIN
Neptune_prem ON Neptune_FN_Analysis.PremID = Neptune_prem.premice_id
WHERE SiteID = 36801 and ReadDate BETWEEN #04/21/09# AND #04/27/09#
and OriginCol = 'US 29' and ColID = 1 and ColID <> 0 and Active = 'Y'