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

Total / count query, help please.

Status
Not open for further replies.

Albion

IS-IT--Management
Aug 8, 2000
517
US
I have a table.

Item_NUM (Autonumber)
NCM_Number (Char)
ReasonCode_NUM (Int)
Cost (Int)

If I have in my table:

Item_NUM, NCM_Number, ReasonCode_NUM, Cost
1 2004-01 1 500
2 2004-02 1 800
3 2004-03 2 100
4 2004-04 2 700
5 2004-05 3 900

I need the query to return:

ReasonCode_NUM, Total_Cost, ReasonCode_Count
1 1300 2
2 800 2
3 900 1

Thanks

-Al
 
Try something like this:[tt]
SELECT ReasonCode_NUM, SUM(Cost) AS Total_Cost, COUNT(*) AS ReasonCode_Count
FROM myTable
GROUP BY ReasonCode_NUM
ORDER BY ReasonCode_NUM[/tt]

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top