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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL statement to count # of rows per value of a column

Status
Not open for further replies.

EdAROC

Programmer
Aug 27, 2002
93
US
QBA - Question by example.
Looking for the number of line items per order, ideally in descending order.
Sample Data:
Ord# ItemID
1234 A
1234 B
1235 A
1236 X
1236 Y
1236 Z

Result:
1234 2
1235 1
1236 3
Better yet (descending order):
1236 3
1234 2
1235 1
 
How about this

Assuming table name = Table1
Order number field name = OrderNum
Item field name = Item

SELECT OrderNum, Count(Item) AS CountOfItem
FROM Table1
GROUP BY OrderNum
ORDER BY Count(Item) DESC;

Your basic Access Totals query utilizing Group by and order by.


Andy Baldwin

"Testing is the most overlooked programming language on the books!"

Ask a great question, get a great answer. Ask a vague question, get a vague answer.
Find out how to get great answers FAQ219-2884.
 
Something like...
Code:
SELECT Ord#, Count(Ord#) AS [Line Items]
FROM [COLOR=red]YourTableName[/color]
ORDER BY Ord# DESC


Randy
 
Great!!! Thanks for the help, appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top