不同表值相加 |微软访问

发布于 2024-08-27 07:31:14 字数 331 浏览 3 评论 0原文

如何将两个表的值添加到一个表记录中,例如

项目表:

ID - 自动编号

OrderID - 数字

价格 - 货币

详细信息 - 文本

订单表:

ID - 自动编号

CustomerID - 编号

日期 - 日期

TotalPrice - 货币

TotalPrice 应将所有商品以及将它们添加到 TotalPrice 中的总价格相加,该总价格将收集为创纪录的价值。

How do I get two tables of their values to add up into one table record, e.g.

Item table:

ID - Autonumber

OrderID - Number

Price - Currency

Details - Text

Order table:

ID - Autonumber

CustomerID - Number

Date - Date

TotalPrice - Currency

The TotalPrice should add up all the items and the total price of adding them up into the TotalPrice which would be collected as a record value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光的暖冬 2024-09-03 07:31:14

如果您想在 Access 中使用 SQL 语法对一列数据进行总计,则应将 SUM 关键字与 GROUP BY 结合使用。

在您的情况下,请使用如下所示的内容:

SELECT o.ID, o.CustomerID, o.Date, SUM(i.Price)
FROM Order AS o
LEFT JOIN Item AS i
ON i.OrderID=o.ID
GROUP BY o.ID, o.CustomerID, o.Date

如果您希望将该列存储在订单表中,那么您仍将使用上述语法(或类似的语法)来计算它。

如何在 Access 中使用它取决于您。您可以将其存储为命名查询,并使该查询成为数据表的记录源。或者您可以将此 sql 直接加载到数据表的记录源中。或单一表格。

If you want to total up a column of data using SQL syntax in Access you should use the SUM keyword with GROUP BY.

In your case use this something like this:

SELECT o.ID, o.CustomerID, o.Date, SUM(i.Price)
FROM Order AS o
LEFT JOIN Item AS i
ON i.OrderID=o.ID
GROUP BY o.ID, o.CustomerID, o.Date

If you wish to store that column in the Order table then you would still use the above syntax (or similar) to calculate it.

How you use this inside Access depends on you. You could store this as a named query and make the query the Record Source for a Datasheet. Or you can load this sql directly into the Record Source of a Datasheet. Or a Single Form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文