为什么在使用 UNION 查询而不是 UNION ALL 时会出现溢出错误?UNION 每一侧的查询单独运行良好,每个查询所作用的表是相同的,即具有完全相同结构的实时数据表和存档数据表。
查询作品:
SELECT Format(CVDate([DateID] & " " & [TimeID]),"yyyy/mm/dd hh:nn:ss") & "-" & [RecNum] AS DateTimeRecNumID,
[QC Records].WONum,
[QC Records].InspName1,
[QC Records].QtyInsp,
Nz([008],0)+Nz([011],0)+Nz([012],0)+Nz([013],0)+Nz([014],0)+Nz([015],0)+Nz([016],0)+Nz([017],0)+Nz([018],0)+Nz([019],0)+Nz([020],0)+Nz([022],0)+Nz([023],0)+Nz([029],0)+Nz([035],0)+Nz([036],0)+Nz([037],0)+Nz([040],0)+Nz([041],0)+Nz([044],0)+Nz([045],0)+Nz([046],0)+Nz([047],0)+Nz([048],0)+Nz([050],0)+Nz([052],0)+Nz([055],0)+Nz([057],0)+Nz([059],0)+Nz([060],0)+Nz([062],0)+Nz([064],0)+Nz([066],0)+Nz([070],0)+Nz([072],0)+Nz([075],0)+Nz([077],0)+Nz([080],0)+Nz([081],0)+Nz([082],0)+Nz([083],0)+Nz([084],0)+Nz([085],0)+Nz([086],0)+Nz([088],0)+Nz([095],0)+Nz([096],0)+Nz([097],0)+Nz([111],0)+Nz([113],0)+Nz([115],0)+Nz([116],0)+Nz([117],0)+Nz([118],0)+Nz([119],0)+Nz([120],0)+Nz([121],0)+Nz([122],0)+Nz([123],0)+Nz([124],0)+Nz([125],0)+Nz([126],0)+Nz([127],0)+Nz([128],0)+Nz([129],0)+Nz([130],0)+Nz([130],0) AS SumFaults,
1-([SumFaults]/[QtyInsp]) AS PassRate,
[QC Records].ItemNum
FROM [QC Records]
WHERE ((([QC Records].ProdSrc)="Production"))
UNION ALL
SELECT Format(CVDate([DateID] & " " & [TimeID]),"yyyy/mm/dd hh:nn:ss") & "-" & [RecNum] AS DateTimeRecNumID,
[QC Records (Archive)].WONum,
[QC Records (Archive)].InspName1,
[QC Records (Archive)].QtyInsp,
Nz([008],0)+Nz([011],0)+Nz([012],0)+Nz([013],0)+Nz([014],0)+Nz([015],0)+Nz([016],0)+Nz([017],0)+Nz([018],0)+Nz([019],0)+Nz([020],0)+Nz([022],0)+Nz([023],0)+Nz([029],0)+Nz([035],0)+Nz([036],0)+Nz([037],0)+Nz([040],0)+Nz([041],0)+Nz([044],0)+Nz([045],0)+Nz([046],0)+Nz([047],0)+Nz([048],0)+Nz([050],0)+Nz([052],0)+Nz([055],0)+Nz([057],0)+Nz([059],0)+Nz([060],0)+Nz([062],0)+Nz([064],0)+Nz([066],0)+Nz([070],0)+Nz([072],0)+Nz([075],0)+Nz([077],0)+Nz([080],0)+Nz([081],0)+Nz([082],0)+Nz([083],0)+Nz([084],0)+Nz([085],0)+Nz([086],0)+Nz([088],0)+Nz([095],0)+Nz([096],0)+Nz([097],0)+Nz([111],0)+Nz([113],0)+Nz([115],0)+Nz([116],0)+Nz([117],0)+Nz([118],0)+Nz([119],0)+Nz([120],0)+Nz([121],0)+Nz([122],0)+Nz([123],0)+Nz([124],0)+Nz([125],0)+Nz([126],0)+Nz([127],0)+Nz([128],0)+Nz([129],0)+Nz([130],0)+Nz([130],0) AS SumFaults,
1-([SumFaults]/[QtyInsp]) AS PassRate,
[QC Records (Archive)].ItemNum
FROM [QC Records (Archive)]
WHERE ((([QC Records (Archive)].ProdSrc)="Production"));
不起作用(区别是 UNION 之后的“ALL”:
SELECT Format(CVDate([DateID] & " " & [TimeID]),"yyyy/mm/dd hh:nn:ss") & "-" & [RecNum] AS DateTimeRecNumID,
[QC Records].WONum,
[QC Records].InspName1,
[QC Records].QtyInsp,
Nz([008],0)+Nz([011],0)+Nz([012],0)+Nz([013],0)+Nz([014],0)+Nz([015],0)+Nz([016],0)+Nz([017],0)+Nz([018],0)+Nz([019],0)+Nz([020],0)+Nz([022],0)+Nz([023],0)+Nz([029],0)+Nz([035],0)+Nz([036],0)+Nz([037],0)+Nz([040],0)+Nz([041],0)+Nz([044],0)+Nz([045],0)+Nz([046],0)+Nz([047],0)+Nz([048],0)+Nz([050],0)+Nz([052],0)+Nz([055],0)+Nz([057],0)+Nz([059],0)+Nz([060],0)+Nz([062],0)+Nz([064],0)+Nz([066],0)+Nz([070],0)+Nz([072],0)+Nz([075],0)+Nz([077],0)+Nz([080],0)+Nz([081],0)+Nz([082],0)+Nz([083],0)+Nz([084],0)+Nz([085],0)+Nz([086],0)+Nz([088],0)+Nz([095],0)+Nz([096],0)+Nz([097],0)+Nz([111],0)+Nz([113],0)+Nz([115],0)+Nz([116],0)+Nz([117],0)+Nz([118],0)+Nz([119],0)+Nz([120],0)+Nz([121],0)+Nz([122],0)+Nz([123],0)+Nz([124],0)+Nz([125],0)+Nz([126],0)+Nz([127],0)+Nz([128],0)+Nz([129],0)+Nz([130],0)+Nz([130],0) AS SumFaults,
1-([SumFaults]/[QtyInsp]) AS PassRate,
[QC Records].ItemNum
FROM [QC Records]
WHERE ((([QC Records].ProdSrc)="Production"))
UNION
SELECT Format(CVDate([DateID] & " " & [TimeID]),"yyyy/mm/dd hh:nn:ss") & "-" & [RecNum] AS DateTimeRecNumID,
[QC Records (Archive)].WONum,
[QC Records (Archive)].InspName1,
[QC Records (Archive)].QtyInsp,
Nz([008],0)+Nz([011],0)+Nz([012],0)+Nz([013],0)+Nz([014],0)+Nz([015],0)+Nz([016],0)+Nz([017],0)+Nz([018],0)+Nz([019],0)+Nz([020],0)+Nz([022],0)+Nz([023],0)+Nz([029],0)+Nz([035],0)+Nz([036],0)+Nz([037],0)+Nz([040],0)+Nz([041],0)+Nz([044],0)+Nz([045],0)+Nz([046],0)+Nz([047],0)+Nz([048],0)+Nz([050],0)+Nz([052],0)+Nz([055],0)+Nz([057],0)+Nz([059],0)+Nz([060],0)+Nz([062],0)+Nz([064],0)+Nz([066],0)+Nz([070],0)+Nz([072],0)+Nz([075],0)+Nz([077],0)+Nz([080],0)+Nz([081],0)+Nz([082],0)+Nz([083],0)+Nz([084],0)+Nz([085],0)+Nz([086],0)+Nz([088],0)+Nz([095],0)+Nz([096],0)+Nz([097],0)+Nz([111],0)+Nz([113],0)+Nz([115],0)+Nz([116],0)+Nz([117],0)+Nz([118],0)+Nz([119],0)+Nz([120],0)+Nz([121],0)+Nz([122],0)+Nz([123],0)+Nz([124],0)+Nz([125],0)+Nz([126],0)+Nz([127],0)+Nz([128],0)+Nz([129],0)+Nz([130],0)+Nz([130],0) AS SumFaults,
1-([SumFaults]/[QtyInsp]) AS PassRate,
[QC Records (Archive)].ItemNum
FROM [QC Records (Archive)]
WHERE ((([QC Records (Archive)].ProdSrc)="Production"));
错误是“溢出”
我还尝试对 UNION ALL 查询执行 SELECT DISTINCT 查询,它也给了我“溢出”错误......??