私が望む日付/時刻フィールドでMax(SampleDateTime)またはMin()を使用すると、クエリは1の値を返しますが、MaxまたはMinを省略すると値は返されません。私はすべての値を返すが、私はこれを把握することはできない。SQL:日付範囲の選択
すべての品質サンプルは、本番稼動の開始時間と停止時間の間に入れたいです。
RunSamples:
Select Max([SampleDateTime])
FROM [QualitySamples] AS [GoodSamples]
WHERE [GoodSamples].[SampleDateTime] >= [ProductionRuns_tbl].[RunStartDate]
AND [GoodSamples].[SampleDateTime] <= [ProductionRuns_tbl].[RunEndDate]
ProductionRuns_tbl:
RunStartDate RunEndDate
2017年1月1日12 AM 1/5/17 12 AM
...
QualitySamples TBL:
ID SampleDateTime
1 1/1/2017 2 am
2 1/1/2017 3 am
...
ここでは、完全なSQLコードです:
SELECT ProductionRuns_tbl.RunName, ProductionRuns_tbl.RunStartDate,
ProductionRuns_tbl.RunEndDate,
(Select Max([SampleDateTime])
FROM [QualitySamples] AS [GoodSamples]
WHERE [GoodSamples].[SampleDateTime] >= [ProductionRuns_tbl].[RunStartDate]
AND [GoodSamples].[SampleDateTime] <= [ProductionRuns_tbl].[RunEndDate])
AS RunSamples
FROM ProductionRuns_tbl
WHERE (((ProductionRuns_tbl.RunName)=[Forms]![Home]![RunName]));
私達にあなたのデータを表示してください。 RunStartDateとRunEndDateの2つの日付の間に実際のデータがありますか? – Joe
あなたはMAXを使用しているので、1つの値しか得られません。 – FLICKER
右 - 私がMAXを削除した場合、クエリから値が得られない – shwan