以下は、Microsoft Access での私の SQL です。サブクエリに基づいてデータを選択したい。
サブクエリを個別に実行しても問題ありません。30秒以内に結果を返します。しかし、次のすべての SQL を実行すると、ms アクセスからの応答がありません。クエリを実行するのは忙しいようですが、結果が返されません。
SELECT '2012/8' AS [Period],
monthno,
[cluster],
'Transfer in' AS Remark,
Count(*) AS [number],
'4' AS [sorting]
FROM [2012],
namesort
WHERE monthno = 244
AND ( div <> 'XXX'
OR div IS NULL )
AND hc = 1
AND [2012].post = namesort.post
AND monthno BETWEEN namesort.monthno_start AND namesort.monthno_end
AND [2012].term <> 'Temporary'
AND empid IN (SELECT empid
FROM (SELECT empid,
[cluster],
Count(*) AS [empid no]
FROM (SELECT empid,
cluster
FROM [assignment]
INNER JOIN yearmonth
ON [assignment].[year month]
=
yearmonth.[year month]
WHERE yearmonth.[monthno] = 243
AND [assignment].hc = 1
AND [assignment].term <> 'Temporary'
UNION
SELECT empid,
[cluster]
FROM [2012]
WHERE monthno = 244
AND [2012].term <> 'Temporary'
AND ( div <> 'XXX'
OR div IS NULL )
AND hc = 1)
GROUP BY [empid],
[cluster]
HAVING Count(*) = 1)
GROUP BY empid
HAVING Count(*) > 1)
GROUP BY monthno,
[cluster]