Different tables values add up | Microsoft Access
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.
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.
精彩评论