純粋な SQL ソリューションの場合、少なくとも0 から 1439 までの値を含む単一の長整数列を持つ [Numbers] テーブルを使用できます。
Integer
-------
0
1
2
3
...
1439
[X] テーブルのデータを取得し、(1) 日付のみ、(2) 午前 0 時からの分数を示す 2 つの列を追加する[X_with_minutes]という名前の保存済みクエリを Access で作成することから始めることができます...
SELECT X.*,
DateSerial(Year([Dates]), Month([Dates]), Day([Dates])) AS JustDate,
DateDiff("n", DateSerial(Year([Dates]), Month([Dates]), Day([Dates])), [Dates]) AS DayMinutes
FROM X;
...戻る:
Dates Number1 Number2 JustDate DayMinutes
------------------- ------- ------- ---------- ----------
2000-01-01 00:00:00 0.3 4 2000-01-01 0
2000-01-01 00:02:00 0.5 5 2000-01-01 2
2000-01-01 00:05:00 0.8 4 2000-01-01 5
[X_minutes_all]という名前の別の保存済みクエリを Access に作成して、[X] の各日のすべての分を生成できます...
SELECT DISTINCT X_with_minutes.JustDate, Numbers.Integer AS DayMinutes
FROM X_with_minutes, Numbers
WHERE Numbers.Integer BETWEEN 0 AND 1439;
...戻る:
JustDate DayMinutes
---------- ----------
2000-01-01 0
2000-01-01 1
2000-01-01 2
2000-01-01 3
...
2000-01-01 1439
これで、不足している分を返すクエリを作成し、そのクエリを[X_missing_minutes]として保存できます。
SELECT * FROM X_Minutes_all
WHERE NOT EXISTS
(
SELECT * FROM X_with_minutes
WHERE X_with_minutes.JustDate=X_minutes_all.JustDate
AND X_with_minutes.DayMinutes=X_minutes_all.DayMinutes
);
...戻る:
JustDate DayMinutes
---------- ----------
2000-01-01 1
2000-01-01 3
2000-01-01 4
2000-01-01 6
2000-01-01 7
2000-01-01 8
...
2000-01-01 1439
欠落している分の「次の」分の値を見つけるには、現在の値を超える最小 (MIN) 値を見つける必要があります。そのクエリを次のように作成し、[X_next_minutes] ...として保存できます。
SELECT X_missing_minutes.JustDate,
X_missing_minutes.DayMinutes,
(
SELECT MIN(DayMinutes)
FROM X_with_minutes
WHERE X_with_minutes.JustDate=X_missing_minutes.JustDate
AND X_with_minutes.DayMinutes>X_missing_minutes.DayMinutes
) AS NextMinute
FROM X_missing_minutes;
...戻る...
JustDate DayMinutes NextMinute
---------- ---------- ----------
2000-01-01 1 2
2000-01-01 3 5
2000-01-01 4 5
2000-01-01 6 <NULL>
2000-01-01 7 <NULL>
2000-01-01 8 <NULL>
...
2000-01-01 1439 <NULL>
これを使用して、不足している分の [X] 値を返すことができます...
SELECT DateAdd("n", X_next_minutes.DayMinutes, X_next_minutes.JustDate) AS Dates,
X_with_minutes.Number1, X_with_minutes.Number2
FROM X_next_minutes INNER JOIN X_with_minutes
ON X_next_minutes.JustDate=X_with_minutes.JustDate
AND X_next_minutes.NextMinute=X_with_minutes.DayMinutes;
...戻る...
Dates Number1 Number2
------------------- ------- -------
2000-01-01 00:01:00 0.5 5
2000-01-01 00:03:00 0.8 4
2000-01-01 00:04:00 0.8 4
...そして、元の [X] を使用して UNION ALL を追加するだけで、最終結果を生成できます...
SELECT DateAdd("n", X_next_minutes.DayMinutes, X_next_minutes.JustDate) AS Dates,
X_with_minutes.Number1, X_with_minutes.Number2
FROM X_next_minutes INNER JOIN X_with_minutes
ON X_next_minutes.JustDate=X_with_minutes.JustDate
AND X_next_minutes.NextMinute=X_with_minutes.DayMinutes
UNION ALL
SELECT * FROM X
ORDER BY 1;
...戻る...
Dates Number1 Number2
------------------- ------- -------
2000-01-01 00:00:00 0.3 4
2000-01-01 00:01:00 0.5 5
2000-01-01 00:02:00 0.5 5
2000-01-01 00:03:00 0.8 4
2000-01-01 00:04:00 0.8 4
2000-01-01 00:05:00 0.8 4