将 Access table 中的数据转换为新 table 中的多行
Transform data in an Access table to multiple rows in a new table
我在 Access 中有一个 table 类似于下面的第一个,其中包含事务行。这些事务可以针对两个单独的产品:ProductOne 和 ProductTwo。我显示了两笔交易 - 一笔用于单一产品,另一笔用于两种产品。
我现有的 table 包含两种可用产品的成本和销售额列。我的目标是将我所拥有的转换为 table,在两个单独的行中列出 COS 和应付账款(来自第一个 table 中的产品成本金额)。然后我需要为零售做同样的事情(从产品销售列和第一个 table 中的金额)。
对于第一个(现有)table 中的每一行,结果 table 中的每个产品将有三个单独的行(COS、应付账款和零售)。例如,客户 Smith 在结果 table 中将有 3 行,因为他们只购买了 ProductOne。但是对于客户 Jones,结果 table 中会有 6 行,因为他们购买了两种产品。
是否有可以实现此目的的查询?我觉得这要么相当复杂,要么我想多了。
我认为您需要 运行 一系列查询(以插入 ProductOne Cost/Payable/Retail 和 ProductTwo Cost/Payable/Retail)。
仅查看 Product1,您的查询应如下所示:
INSERT INTO tblCustomer2
(CustomerNumber, CustomerName, PostingCategory, PostingAmount, Description)
SELECT
CustomerNumber, CustomerName, "COS", ProductOneCost, "ProductOne"
FROM tblCustomer1
WHERE ProductOneCost>0
INSERT INTO tblCustomer2
(CustomerNumber, CustomerName, PostingCategory, PostingAmount, Description)
SELECT
CustomerNumber, CustomerName, "Payable", -ProductOneCost, "ProductOne"
FROM tblCustomer1
WHERE ProductOneCost>0
INSERT INTO tblCustomer2
(CustomerNumber, CustomerName, PostingCategory, PostingAmount, Description)
SELECT
CustomerNumber, CustomerName, "Retail", -ProductOneSale, "ProductOne"
FROM tblCustomer1
WHERE ProductOneCost>0
然后对 ProductTwo 执行类似的过程。
此致,
我在 Access 中有一个 table 类似于下面的第一个,其中包含事务行。这些事务可以针对两个单独的产品:ProductOne 和 ProductTwo。我显示了两笔交易 - 一笔用于单一产品,另一笔用于两种产品。
我现有的 table 包含两种可用产品的成本和销售额列。我的目标是将我所拥有的转换为 table,在两个单独的行中列出 COS 和应付账款(来自第一个 table 中的产品成本金额)。然后我需要为零售做同样的事情(从产品销售列和第一个 table 中的金额)。
对于第一个(现有)table 中的每一行,结果 table 中的每个产品将有三个单独的行(COS、应付账款和零售)。例如,客户 Smith 在结果 table 中将有 3 行,因为他们只购买了 ProductOne。但是对于客户 Jones,结果 table 中会有 6 行,因为他们购买了两种产品。
是否有可以实现此目的的查询?我觉得这要么相当复杂,要么我想多了。
我认为您需要 运行 一系列查询(以插入 ProductOne Cost/Payable/Retail 和 ProductTwo Cost/Payable/Retail)。
仅查看 Product1,您的查询应如下所示:
INSERT INTO tblCustomer2
(CustomerNumber, CustomerName, PostingCategory, PostingAmount, Description)
SELECT
CustomerNumber, CustomerName, "COS", ProductOneCost, "ProductOne"
FROM tblCustomer1
WHERE ProductOneCost>0
INSERT INTO tblCustomer2
(CustomerNumber, CustomerName, PostingCategory, PostingAmount, Description)
SELECT
CustomerNumber, CustomerName, "Payable", -ProductOneCost, "ProductOne"
FROM tblCustomer1
WHERE ProductOneCost>0
INSERT INTO tblCustomer2
(CustomerNumber, CustomerName, PostingCategory, PostingAmount, Description)
SELECT
CustomerNumber, CustomerName, "Retail", -ProductOneSale, "ProductOne"
FROM tblCustomer1
WHERE ProductOneCost>0
然后对 ProductTwo 执行类似的过程。
此致,