简体   繁体   中英

Different tables values add up | Microsoft Access

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM