首先感谢您花时间审查这个问题。我正在尝试升级旧版 MS Access 数据库的功能以通过 UNION 运算符实现 FULL OUTER JOIN,但是 SELECT 语句包含通过 SUM 和 + 和 * 算术运算符的聚合,当我尝试组合它们时,它们给了我一个时髦的答案这是期望结果的倍数。放轻松,我已经很久没有编程了。
背景信息 1. 无法更改现有架构 2. 查询性能无关紧要 3. 再说一次,我说我没有设计这个架构,我只是让它工作。
我已经尝试实现这些文章中概述的 FULL OUTER JOIN。 http://www.databasejournal.com/features/msaccess/article.php/3516561/Implementing-the-Equivalent-of-a-FULL-OUTER-JOIN-in-Microsoft-Access.htm 完全加入 MS Access
以下是我想要 FULL OUTER JOIN 的每个表的可怕查询,目前它们独立工作。
SELECT [DEPT SALES].Day, (IIf(Sum([DEPT SALES].[Total Sales]) Is Null, 0, Sum([DEPT SALES].[Total Sales]))) +
(IIf(Sum([DEPT SALES].[GST]) Is Null, 0, Sum([DEPT SALES].[GST]))) +
(IIf(Sum([DEPT SALES].[PST]) Is Null, 0, Sum([DEPT SALES].[PST]))) AS [TOTAL SALES]
FROM [DEPT SALES]
WHERE [DEPT SALES].[Biz ID] = "Sk"
GROUP BY [DEPT SALES].Day;
SELECT [TILL].Day, (IIf(Sum(TILL.[2 Count]) Is Null, 0, Sum(TILL.[2 Count]) * 2)) +
(IIf(Sum(TILL.[5 Count]) Is Null, 0, Sum(TILL.[5 Count]) * 5)) +
(IIf(Sum(TILL.[10 Count]) Is Null, 0, Sum(TILL.[10 Count]) * 10)) +
(IIf(Sum(TILL.[20 Count]) Is Null, 0, Sum(TILL.[20 Count]) * 20)) +
(IIf(Sum(TILL.[50 Count]) Is Null, 0, Sum(TILL.[50 Count]) * 50)) +
(IIf(Sum(TILL.[100 Count]) Is Null, 0, Sum(TILL.[100 Count]) * 100)) +
(IIf(Sum(TILL.[Change]) Is Null, 0, Sum(TILL.[Change]))) AS [TOTAL NOTES], ( IIf(Sum(TILL.[Check 1]) Is Null, 0, Sum(TILL.[Check 1])) ) +
( IIf(Sum(TILL.[Check 2]) Is Null, 0, Sum(TILL.[Check 2])) ) +
( IIf(Sum(TILL.[Check 3]) Is Null, 0, Sum(TILL.[Check 3])) ) +
( IIf(Sum(TILL.[Check 4]) Is Null, 0, Sum(TILL.[Check 4])) ) +
( IIf(Sum(TILL.[Check 5]) Is Null, 0, Sum(TILL.[Check 5])) ) +
( IIf(Sum(TILL.[Check 6]) Is Null, 0, Sum(TILL.[Check 6])) ) +
( IIf(Sum(TILL.[Check 7]) Is Null, 0, Sum(TILL.[Check 7])) ) +
( IIf(Sum(TILL.[Check 8]) Is Null, 0, Sum(TILL.[Check 8])) ) +
( IIf(Sum(TILL.[Check 9]) Is Null, 0, Sum(TILL.[Check 9])) ) +
( IIf(Sum(TILL.[Check 9]) Is Null, 0, Sum(TILL.[Check 9])) ) AS [TOTAL CHECK], IIf(Sum(TILL.MC) Is Null, 0, Sum(TILL.MC)) AS [TOTAL MC], IIf(Sum(TILL.Visa) Is Null, 0, Sum(TILL.Visa)) AS [TOTAL VISA], IIf(Sum(TILL.[Debit Card]) Is Null, 0, Sum(TILL.[Debit Card])) AS [TOTAL DEBIT CARD], IIf(Sum(TILL.USD) Is Null, 0, Sum(TILL.USD)) AS [TOTAL USD], (IIf(Sum(TILL.[Pd Out 1]) Is Null, 0, Sum(TILL.[Pd Out 1])) + IIf(Sum(TILL.[Pd Out 2]) Is Null, 0, Sum(TILL.[Pd Out 2])) ) AS [TOTAL PD OUT], IIf(Sum(TILL.[US ex Pd Out]) Is Null, 0, Sum(TILL.[Us ex Pd Out])) AS [TOTAL US EX PD OUT]
FROM TILL
WHERE ( ([TILL].[Biz ID])="Sk")
GROUP BY [TILL].Day;
将不胜感激,任何帮助。为了帮助可视化,它的销售报告系统可以报告每天的总金额(从多个收银台汇总)以及部门销售额。需要 FULL OUTER JOIN,因为 TILL & DEPT SALES 数据并不总是在同一天上传。