Yes: Orders and Order Details are 2 tables. The Orders table holds the
header info (order number, date, client), and the Order Details holds the
line items (quantity, product, unitprice), since one order can contain
many
rows. To see an example, open the Northwind sample database that installs
with Access.
The 2nd part of the question may become clearer after you see the
example.
Allen,
I'm comfused by the example you referenced. It includes the code below.
However, I can't figure out the difference between [Orders] and [Order
Details]. Are there two tables (I only have one)? Or is [Order Details]
the
'dummy' table that is really just [Orders], and if so is there an error
in
the syntax below?
Also, what if I want a sum-to-date that spans multiple years of data?
Richard
SELECT Year([Orders].[OrderDate]) AS TheYear,
Month([Orders].[OrderDate]) AS TheMonth,
Sum([Order Details].[Quantity]*[Order Details].[UnitPrice]) AS
MonthAmount,
(SELECT Sum(OD.Quantity * OD.UnitPrice) AS YTD
FROM Orders AS A INNER JOIN [Order Details] AS OD ON A.OrderID =
OD.OrderID
WHERE A.OrderDate >= DateSerial(Year([Orders].[OrderDate]),1,1)
AND A.OrderDate < DateSerial(Year([Orders].[OrderDate]),
Month([Orders].[OrderDate]) + 1, 1))
AS YTDAmount
FROM Orders INNER JOIN [Order Details] ON Orders.OrderID = [Order
Details].OrderID
GROUP BY Year([Orders].[OrderDate]), Month([Orders].[OrderDate]);
--
Richard
:
Use a totals query to get the totals for a period (e.g. a month.)
Then use a subquery to get the progressive total.
The Year-to-date example should illustrate how:
http://allenbrowne.com/subquery-01.html#YTD
I have labor data for employees given by hours worked on a given day.
Eg. Tom, 5-hrs, 5-Jan-2001
What I need is cumulative hours worked by month:
E.g. Tom, 100-hours-to-date, Jan-2001
How can I use Access to generate cumulative-hours-to-date by month
from
hours-worked-on-given-days?
Note: It’s something I could get from Excel Pivot table, but I have
well
over 60,000 records (in the millions).