关于c#:如何将两个表与计算MS Access合并?

How to merge two tables with computation MS Access?

我有2个表,几乎具有相同的属性。假设在表1中我具有这些属性。

1
2
Item        Quantity        Unit Net Price        Total Net Price
asd            2                 22                    44

而且,在表2中:

1
2
Item        Quantity        Unit Gross Price
asd            1                 20

您可以看到每个表的区别。

Unit Net Price = Unit Gross Price * 1.10

Total Net Price = Unit Net Price * Quantity

我需要将table2插入到table1并同时Unit Net Price
Total Net Price将被计算。我无法为此做出正确的查询语句。到目前为止,我正在处理此声明。

1
"INSERT INTO [table1] ([Item], [Quantity], [Unit Net Price], [Total Net Price]) SELECT * FROM [table2] WHERE [Unit Net Price] = [Unit Gross Price] * 1.10 AND [Total Net Price] = [Quantity] * [Total Net Price]"

我正在使用OleDBCommand进行此查询。任何人都可以为我提供正确的查询语句或适当的解决方案?


对于SQL解决方案,请使用此选项。
计算进入SELECT子句,而不是WHERE子句。

还请注意,您不能使用刚刚计算的字段([单位净价])来计算另一个字段([总净价]),所有计算都必须基于表2中的字段。

1
2
3
4
5
6
7
INSERT INTO [table1] ([Item], [Quantity], [Unit Net Price], [Total Net Price])
SELECT
    [Item],
    [Quantity],
    [Unit Gross Price] * 1.10 AS [Unit Net Price],
    [Quantity] * [Unit Gross Price] * 1.10 AS [Total Net Price]
FROM [table2]