J
John T Ingato
Lets say I have a few tables;
table1 Customers: CustomerID, Name,Address,..
table2: Products: ProductID, Description, Cost
table3: Transactions: CustomerID, ProdID, Quantity
with the following dataset:
CustID ProdID Quantity
BOB1 1001 10
BOB1 1002 5
JOE1 1004 5
SMS 1001 10
SMS 1002 10
SMS 1004 5
BOB1 1001 10
SMS 1002 5
BOB1 1004 10
If I run a totals query based on ProdID to show performance of each item;
....
Select ProdID, Sum(Quantity) as Total From table3 Group By ProdID
I can get the following:
ProdID Total
1001 30
1002 10
1004 20
But what if I want to know number of "distinct" accounts that were part of
that calculation... e.g.
ProdID Total Accts
1001 30 2 ... 2 Bobs + 1 SMS or 2 separate
accounts
1002 10 2 ...(1 BOB) + (1 SMS) or 2 separate
accounts
1004 10 3 ...(1 BOB) + (1 SMS) + (1 JOE) or 3
separate accounts
How do I accomplish this?
I tried entering in the totals query, a field value of - Accts:
Count(Select Distinct ProdID from table 3). The failure message I get is
"At most one record can be returned from this subquery"
TRY 2:
SELECT DISTINCT table3.ProdID,
Sum(table3.Quantity AS [Total],
Count(A.StoreNumber) AS StoresReporting
FROM table3 INNER JOIN table3 AS A
ON table3.ItemNumber = A.ItemNumber
GROUP BY tblCalculatedSalesDataHomeDepot.ItemNumber;
This one jus ran forever without any result.. It seemed to hang up.
CAN SOMEONE PLEASE TELL ME HOW TO DO THIS???
table1 Customers: CustomerID, Name,Address,..
table2: Products: ProductID, Description, Cost
table3: Transactions: CustomerID, ProdID, Quantity
with the following dataset:
CustID ProdID Quantity
BOB1 1001 10
BOB1 1002 5
JOE1 1004 5
SMS 1001 10
SMS 1002 10
SMS 1004 5
BOB1 1001 10
SMS 1002 5
BOB1 1004 10
If I run a totals query based on ProdID to show performance of each item;
....
Select ProdID, Sum(Quantity) as Total From table3 Group By ProdID
I can get the following:
ProdID Total
1001 30
1002 10
1004 20
But what if I want to know number of "distinct" accounts that were part of
that calculation... e.g.
ProdID Total Accts
1001 30 2 ... 2 Bobs + 1 SMS or 2 separate
accounts
1002 10 2 ...(1 BOB) + (1 SMS) or 2 separate
accounts
1004 10 3 ...(1 BOB) + (1 SMS) + (1 JOE) or 3
separate accounts
How do I accomplish this?
I tried entering in the totals query, a field value of - Accts:
Count(Select Distinct ProdID from table 3). The failure message I get is
"At most one record can be returned from this subquery"
TRY 2:
SELECT DISTINCT table3.ProdID,
Sum(table3.Quantity AS [Total],
Count(A.StoreNumber) AS StoresReporting
FROM table3 INNER JOIN table3 AS A
ON table3.ItemNumber = A.ItemNumber
GROUP BY tblCalculatedSalesDataHomeDepot.ItemNumber;
This one jus ran forever without any result.. It seemed to hang up.
CAN SOMEONE PLEASE TELL ME HOW TO DO THIS???