Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distinct Count Problem

Status
Not open for further replies.

infomania

Programmer
Oct 27, 2002
148
I have a data set that looks like this:
ITEM QTY BoxNbr
ABC 6 1
ABC 6 1
ABC 6 1
ABC 6 2
ABC 6 2
ABC 6 2

The query result I want is:
ITEM Sum-Qty Boxes
ABC 36 2

I want to count(distinct BoxNbr) (as in SQL). How can I do this in Access?
 
infomania:
The Jet does a great effort adopting the main sql keys not all them, and we must accept its lack of power conpared with sql t-slq. Even so we always can find ways to gracefully overcome these non frequent issues.
for you question, what you want to do with a single line in access is just not possible, the easier you can do it is having two queries, one to group and one to get the totals; something like this
Query 1
Code:
SELECT Table1.Item, Sum(Table1.Qty) AS SumOfQty, Table1.box, First(Table1.box) AS FirstOfbox
FROM table1
GROUP BY Table1.Item, Table1.box;

Query 2
SELECT Query1.Item, Sum(Query1.SumOfQty) AS SumOfSumOfQty, Count(Query1.box) AS CountOfbox
FROM Query1
GROUP BY Query1.Item;

Good luck

Estuardo
 
One way...

1. create a query that groups BoxNbr, Where Item = "ABC" - (Qry1)
2. create a query that counts the number of records (boxes) produced from Qry1 - (Qry2)
3. create a query that sums QTY, Where Item = "ABC" - (Qry3)
4. create a query that includes the 3 fields from Qry2 and Qry3.

All 4 queries above are just select queries.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top